#_2022 #kyc
UK sanctions for OSINT / KYC searches. Setup here for full text search in SQLite.
Link:
Script:
```py
# migrate_uk_sanctions_list_table.py
import sqlite3
import pandas as pd
import requests
import os
# --------------------------------------------------------------- #
# https://www.gov.uk/government/publications/the-uk-sanctions-list
# this file must be manually downloaded, then placed in the static
# data directory as uk_sanctions.csv. This doesn't take long at
# all, but it super annoying. Use the 'new ods format',
# TODO: Make an RPA script that downloads this data and moves it
# into the static_data directory so this can be totally automated
# --------------------------------------------------------------- #
def create_uk_sanctions_db():
# ------------------------------------ #
# Delete the DB if it exists
# ------------------------------------ #
if os.path.exists("db_uk_sanctions.db"):
os.remove("db_uk_sanctions.db")
# ------------------------------------ #
# Make the db
# ------------------------------------ #
db = sqlite3.connect('db_uk_sanctions.db')
cursor = db.cursor()
cursor.close()
db.close()
# ------------------------------------ #
# Make the dataframe
# ------------------------------------ #
# make dataframe from the extract
uk_df = pd.read_csv('static_data/uk_sanctions.csv', encoding="UTF-8")
uk_df = uk_df.astype(str)
# rename the column titles to remove spaces and camelcase
column_titles = []
for title in uk_df.columns:
column_titles.append(title.replace(' ','_').replace('-','_').replace(',','').replace('.','').replace('/','_').replace('(','').replace(')','').lower())
uk_df.columns = column_titles
# make a formatted string of the column headers for later use
headers = ''
for title in column_titles:
headers += title
headers += ','
# ------------------------------------ #
# Insert data to db
# ------------------------------------ #
conn = sqlite3.connect('db_uk_sanctions.db', check_same_thread=False)
uk_df.to_sql(name='uk_sanctions', con=conn, if_exists='replace', index=False)
# ------------------------------------ #
# Make the virtual table
# ------------------------------------ #
conn.execute(f'''
CREATE VIRTUAL TABLE v_uk_sanctions
USING FTS5 (
{headers[:-1]}
)
;
'''
)
conn.execute(f'''
INSERT INTO v_uk_sanctions (
{headers[:-1]}
)
SELECT
{headers[:-1]}
FROM uk_sanctions
;
'''
)
conn.commit()
conn.execute('''DROP TABLE uk_sanctions;''')
conn.execute('''VACUUM;''')
# # ------------------------------------ #
# # Close the database
# # ------------------------------------ #
conn.close()
# ------------------------------------ #
# print statement
# ------------------------------------ #
print(' ')
print(len(uk_df))
print(' ')
print('--------------------------------------------')
print('--------------------------------------------')
print(' UK Sanctions Database Build Complete ')
print('--------------------------------------------')
print('--------------------------------------------')
# create_uk_sanctions_db()
```