Advertisement
Guest User

SQL_rossmann

a guest
May 2nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. import pymysql.cursors
  2. import re
  3.  
  4. cnx = pymysql.connect(host = "localhost", user = "root", password="ptekm8n8", db ="Rossmann")
  5. cursor = cnx.cursor()
  6.  
  7. adress = "SELECT ADRESSE from Filialen"
  8. cursor.execute(adress)
  9.  
  10. a = cursor.fetchall()
  11.  
  12.  
  13. sql_adress = []
  14. s = []
  15.  
  16. cursor.execute(adress)
  17. for i in a:
  18.     item = tuple(i[0].split(","))
  19.     sql_adress.append(item[0])
  20.     s.append(item[1].strip()) #strip() fordi "," bliver tilføjet som en værdi
  21.  
  22. city = []
  23. zipcode = []
  24. for i in s:
  25.     h = re.findall(r'\d{1,10}', i)
  26.     o = re.findall(r'\D{1,100}', i)
  27.     zipcode.append(h)
  28.     city.append(o)
  29.  
  30.  
  31. # new_zipcode = []
  32. # print(zipcode)
  33. # for item in zipcode:
  34. #     for inner in item:
  35. #         new_zipcode.append(inner)
  36.  
  37. sql_zipcode = [item for i in zipcode for item in i] #samme som ovenstående :)
  38. sql_city = [item.strip() for i in city for item in i] #samme princip, strip() fordi der var et whitespace i starten af hver værdi.
  39.  
  40. print(sql_city)
  41. print(sql_zipcode)
  42. print(sql_adress)
  43.  
  44. chain = 'SELECT kette from Filialen'
  45. cursor.execute(chain)
  46.  
  47. b = cursor.fetchall()
  48. sql_chain = [item for i in b for item in i]
  49. print(sql_chain)
  50.  
  51. #This little piggy went to the market, this little piggy stayed home, this little piggy had roast beef, this little piggy had none
  52. #                            _
  53. #  _._ _..._ .-',     _.._(`))
  54. # '-. `     '  /-._.-'    ',/
  55. #    )         \            '.
  56. #   / _    _    |             \
  57. #  |  a    a    /              |
  58. #  \   .-.                     ;
  59. #   '-('' ).-'       ,'       ;
  60. #      '-;           |      .'
  61. #         \           \    /
  62. #         | 7  .__  _.-\   \
  63. #         | |  |  ``/  /`  /
  64. #        /,_|  |   /,_/   /
  65. #           /,_/      '`-'
  66. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement