-
Notifications
You must be signed in to change notification settings - Fork 0
/
nr.py
37 lines (28 loc) · 929 Bytes
/
nr.py
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
26
27
28
29
30
31
32
33
34
35
36
37
import sys
import json
import MySQLdb
from MySQLdb import escape_string as thwart
reload(sys)
sys.setdefaultencoding('ISO-8859-1')
mysql = MySQLdb
connection = mysql.connect(host = "localhost", user = "root", passwd = "HiGroup6!", db = "Easycook")
cursor = connection.cursor()
fname = 'klikk-recipes-backup.json'
str_data = open(fname).read()
json_data = json.loads(str_data)
i = 0
for entry in json_data:
i += 1
print("i", i)
title = entry['title']
ingredients = entry['ingredients']
cursor.execute('''SELECT name_R From Recipe Where name_R='%s';'''%(thwart(title)))
check = cursor.fetchall()
if check!=():
continue
st ="['"+ "', '".join(ingredients)+"']"
print(st)
cursor.execute('''INSERT INTO Recipe (name_R,ingredients,categories,rating) VALUES('%s', '%s', '%s',0);'''%(thwart(title), thwart(st), thwart(st)))
connection.commit()
cursor.close()
connection.close()