· 8 years ago · Apr 13, 2018, 09:12 AM
1import requests
2import sqlite3
3
4con = sqlite3.connect("COINS.db")
5cur = con.cursor()
6
7cur.execute('DROP TABLE IF EXISTS COINS')
8
9cur.execute(
10 "CREATE TABLE COINS (Identifier INTEGER PRIMARY KEY , symbol TEXT, description TEXT);"
11)
12
13r = requests.get('https://api.coindesk.com/v1/bpi/currentprice.json')
14to_db = r.json() # I do not have to do it in json, CSV would also be another
15 # solution but the data that is been stored can not be static.
16 # It has to autmagically fetch the data from API-endpoint
17
18cur.execute("INSERT INTO COINS (Identifier, symbol, description) VALUES (?, ?, ?);", to_db)
19
20con.commit()
21con.close()