You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
677 B
21 lines
677 B
import csv
|
|
import sys
|
|
|
|
results = []
|
|
|
|
print("DROP TABLE IF EXISTS rate;")
|
|
print("CREATE TABLE IF NOT EXISTS rate (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, date DATE, currency TEXT, rate FLOAT);");
|
|
|
|
with open(sys.argv[1]) as f:
|
|
reader = csv.DictReader(f)
|
|
for currencies in reader:
|
|
date = currencies['Date']
|
|
del currencies['Date']
|
|
|
|
for currency in currencies.keys():
|
|
# skip the blank ones
|
|
if currency != '':
|
|
rate = currencies[currency]
|
|
rate = rate == "N/A" and "null" or rate
|
|
|
|
print(f"INSERT INTO rate (date, currency, rate) VALUES ('{date}', '{currency}', { rate });")
|
|
|