1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
json_response = urllib.request.urlopen("http://xxx/file.json")
data = json.load(json_response)
headers = ""
attr_allocate = ""
headers_dict = dict(data["data"][0])
for i in headers_dict:
headers += '"' + I + '"' + ' VARCHAR(255),'
headers = headers.strip(',')
#Table creation
create_request = "CREATE TABLE TAB (" + headers + ")"
cursor.execute(create_request)
con.commit()
for i in data["data"]
#Line where I specify all values...
attr_allocate = '\'' + i["name"].replace("'","'\'") + '\'' + ...
insert_request = "INSERT INTO TAB VALUES (" + attr_allocate + ");"
cursor.execute(insert_request)
con.commit()
attr_allocate = "" |
Partager