Advertisement
Guest User

Untitled

a guest
May 20th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1.  
  2.  
  3. # Database for database/Rossman
  4.  
  5. import pymysql
  6. import json
  7. import pymysql.cursors
  8.  
  9. def butikker():
  10. cnx = pymysql.connect(user='root',
  11. password='1234',
  12. host='127.0.0.1',
  13. database='Rossmann')
  14. cursor= cnx.cursor()
  15.  
  16. #hent data
  17. cursor.execute("SELECT* FROM filialen")
  18. results=cursor.fetchall()
  19. exist= cursor.fetchone()
  20.  
  21. cnx.close()
  22.  
  23. cnx = pymysql.connect(user='root',
  24. password='1234',
  25. host='127.0.0.1',
  26. database='jsondb')
  27. cursor = cnx.cursor()
  28.  
  29. # Formater data
  30.  
  31. print(results)
  32. for i in results:
  33. name = i[0]
  34. adresse_ = i[2].split(",")[0]
  35. zipcode =i[2].split(",")[1].lstrip().split(' ')[0]
  36. zipcode_area=i[2].split(",")[1].lstrip().split(' ')[1]
  37.  
  38. query = ('INSERT INTO TyskKonkurenter (Navne_Butik, Postnr, By_Navn, Adresse) VALUES (%s, %s, %s, %s);')
  39. cursor.execute(query, (name, zipcode, zipcode_area, adresse_))
  40. #luk forbindelse til db
  41.  
  42.  
  43.  
  44. cnx.commit()
  45. cnx.close()
  46.  
  47. butikker()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement