#data #kyc #_2022 This is one list I consult when doing KYC checks for individuals affiliated to a deal. Accordingly, I like to prep it for full text search by using SQLite. Link: Script: ```py # migrate_belgium.py import sqlite3 import pandas as pd import os # --------------------------------------------------------------- # # https://finance.belgium.be/en/treasury/financial-sanctions # this file must be manually downloaded, then placed in the static # data directory as belgium_sanctions.csv. # 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_belgium_sanctions_db(): # ------------------------------------ # # Delete the DB if it exists # ------------------------------------ # if os.path.exists("db_belgium_sanctions.db"): os.remove("db_belgium_sanctions.db") # ------------------------------------ # # Make the db # ------------------------------------ # db = sqlite3.connect('db_belgium_sanctions.db') cursor = db.cursor() cursor.close() db.close() # ------------------------------------ # # Make the dataframe # ------------------------------------ # # make dataframe from the extract belgium_df = pd.read_csv('static_data/belgium_sanctions.csv', encoding="UTF-8") belgium_df = belgium_df.astype(str) # rename the column titles to remove spaces and camelcase column_titles = [] for title in belgium_df.columns: column_titles.append(title.replace(' ','_').replace('-','_').replace(',','').replace('.','').replace('/','_').replace('(','').replace(')','').lower()) belgium_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_belgium_sanctions.db', check_same_thread=False) belgium_df.to_sql(name='belgium_sanctions', con=conn, if_exists='replace', index=False) # ------------------------------------ # # Make the virtual table # ------------------------------------ # conn.execute(f''' CREATE VIRTUAL TABLE v_belgium USING FTS5 ( {headers[:-1]} ) ; ''' ) conn.execute(f''' INSERT INTO v_belgium ( {headers[:-1]} ) SELECT {headers[:-1]} FROM belgium_sanctions ; ''' ) conn.commit() conn.execute('''DROP TABLE belgium_sanctions;''') conn.execute('''VACUUM;''') # # ------------------------------------ # # # Close the database # # ------------------------------------ # conn.close() # ------------------------------------ # # print statement # ------------------------------------ # print(' ') print(len(belgium_df)) print(' ') print('--------------------------------------------') print('--------------------------------------------') print(' Belgium Sanctions Database Build Complete ') print('--------------------------------------------') print('--------------------------------------------') # create_belgium_sanctions_db() ```