|
| 1 | +import requests, zipfile, io |
| 2 | +import pandas as pd |
| 3 | +import sqlite3 as sql |
| 4 | + |
| 5 | +#imports functions for downloading data making database |
| 6 | +from mdt_functions import zip_downloader, sql_create_table, db_query, read_sql_string |
| 7 | + |
| 8 | + |
| 9 | +#downloads urrent FDA NDCs. |
| 10 | +z = zip_downloader('https://www.accessdata.fda.gov/cder/ndctext.zip') |
| 11 | + |
| 12 | +#moves FDA files to sqlite database by reading as dataframes |
| 13 | +product = pd.read_csv(z.open('product.txt'),sep='\t',dtype=object,header=0,encoding='cp1252') |
| 14 | +package = pd.read_csv(z.open('package.txt'),sep='\t',dtype=object,header=0,encoding='cp1252') |
| 15 | +sql_create_table('product',product) |
| 16 | +sql_create_table('package',package) |
| 17 | +del product |
| 18 | +del package |
| 19 | + |
| 20 | +#deletes FDA ZIP |
| 21 | +del z |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +#NOTE: Rob's python code to join one of these tables with the rxcui_ndc table goes here |
| 26 | +""" |
| 27 | +rxcui_ndc_string = read_sql_string('rxcui_ndc.sql') |
| 28 | +rxcui_ndc = db_query(rxcui_ndc_string) |
| 29 | +sql_create_table('rxcui_ndc', rxcui_ndc) |
| 30 | +del rxcui_ndc |
| 31 | +""" |
| 32 | + |
| 33 | + |
| 34 | +#TEST!!!!!!!!!!!!!!!! reads record count from created database |
| 35 | +product = db_query("Select count(*) AS records from product limit 1") |
| 36 | +print('DB table product has {0} records'.format(product['records'].iloc[0])) |
| 37 | + |
| 38 | +package = db_query("Select count(*) AS records from package limit 1") |
| 39 | +print('DB table package has {0} records'.format(package['records'].iloc[0])) |
0 commit comments