import json import pymysql new = { 'id': '2023015', 'date': '2023-02-12', 'red': '["02", "03", "14", "21", "29", "32"]', 'blue': '08' } db = { 'host': 'home.rogersun.online', 'user': 'root', 'password': 'Sxzgx1209', 'database': 'lottery' } conn = pymysql.connect(**db) cursor = conn.cursor() # with open('num_new.txt', 'r') as f: # lines = f.readlines() # for line in lines: # j = json.loads(line) # print(j) # cursor.execute('INSERT INTO history (`dateId`,`openDate`,`red`,`blue`) VALUES (%s,%s,%s,%s)', # (j['id'], j['date'], json.dumps(j['red']), j['blue'])) # f.close() cursor.execute('INSERT INTO history (`dateId`,`openDate`,`red`,`blue`) VALUES (%s,%s,%s,%s)', (new['id'], new['date'], new['red'], new['blue'])) cursor.close() conn.commit()