Advertisement
Guest User

Untitled

a guest
May 20th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1.  
  2. # Json database
  3.  
  4. import pymysql
  5. import json
  6.  
  7.  
  8. def json_butikker():
  9. open_json = open('Rossmann.json','r').read()
  10. Rossmann = json.loads(open_json)
  11.  
  12. cnx = pymysql.connect(user='root',
  13. password='1234',
  14. host='127.0.0.1',
  15. database='jsondb')
  16. cursor = cnx.cursor()
  17. for item in Rossmann:
  18. name = item['name']
  19. zipcode = item['stadt'].split(' ')[0]
  20. city =item['stadt'].split(' ')[1]
  21. adress = item['strasse']
  22.  
  23. cursor.execute('INSERT INTO TyskKonkurenter (Navne_Butik, Postnr, By_Navn, Adresse) VALUES (%s, %s, %s, %s)',
  24. (name, zipcode, city, adress))
  25. cnx.commit()
  26. cnx.close()
  27.  
  28.  
  29. json_butikker()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement