Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #HERE IT COMES; THE TRUTH IS HERE
- import pymysql
- import urllib.request, json
- from sqlalchemy.sql.expression import false
- def checkandinsert_zipcode(input_zipcode):
- cnx1 = pymysql.connect(user='root', password='Ettema128611', host='127.0.0.1', database='databasenormala/s')
- cursor1 = cnx1.cursor()
- cursor1.execute("SELECT zipcode_key FROM tabel_zipcode WHERE zipcode = (%s)",input_zipcode)
- cnx1.commit()
- if cursor1.rowcount ==0:
- cursor1.execute("INSERT INTO tabel_zipcode (zipcode) VALUES (%s)", (str(input_zipcode)))
- cnx1.commit()
- else:
- return false
- cursor1.close()
- cnx1.close()
- def checkandinsert_city(input_city):
- cnx1 = pymysql.connect(user='root', password='Ettema128611', host='127.0.0.1', database='databasenormala/s')
- cursor1 = cnx1.cursor()
- cursor1.execute("SELECT city_key FROM tabel_city WHERE city = (%s)",input_city)
- cnx1.commit()
- if cursor1.rowcount ==0:
- cursor1.execute("INSERT INTO tabel_city (city) VALUES (%s)", (str(input_city)))
- cnx1.commit()
- else:
- return false
- cursor1.close()
- cnx1.close()
- def checkandinsert_comp(input_comp):
- cnx1 = pymysql.connect(user='root', password='Ettema128611', host='127.0.0.1', database='databasenormala/s')
- cursor1 = cnx1.cursor()
- cursor1.execute("SELECT comp_key FROM tabel_comp WHERE comp = (%s)",(str(input_comp)))
- cnx1.commit()
- if cursor1.rowcount ==0:
- cursor1.execute("INSERT INTO tabel_comp (comp) VALUES (%s)", (str(input_comp)))
- cnx1.commit()
- else:
- return false
- cursor1.close()
- cnx1.close()
- def checkandinsert_address(input_address, input_zipcode,input_city, input_comp):
- cnx1 = pymysql.connect(user='root', password='Ettema128611', host='127.0.0.1', database='databasenormala/s')
- cursor1 = cnx1.cursor()
- cursor1.execute("SELECT city_key FROM tabel_city WHERE city = (%s)",str(input_city))
- cnx1.commit()
- city_key_fk=str(cursor1.fetchone()[0])
- cursor1.execute("SELECT comp_key FROM tabel_comp WHERE comp = (%s)",str(input_comp))
- cnx1.commit()
- comp_key_fk=str(cursor1.fetchone()[0])
- cursor1.execute("SELECT zipcode_key FROM tabel_zipcode WHERE zipcode = (%s)",str(input_zipcode))
- cnx1.commit()
- zipcode_key_fk=str(cursor1.fetchone()[0])
- cursor1.execute("SELECT * FROM tabel_address WHERE address = \'"+input_address+"\' and zipcode_key = \'"+zipcode_key_fk+"\' and city_key= \'"+city_key_fk+"\'and comp_key=\'"+comp_key_fk+"\'")
- cnx1.commit()
- if cursor1.rowcount ==0:
- cursor1.execute("INSERT INTO tabel_address (address, comp_key, zipcode_key, city_key) VALUES (%s, %s,%s,%s)", (str(input_address),comp_key_fk,zipcode_key_fk, city_key_fk))
- cnx1.commit()
- cursor1.close()
- cnx1.close()
- else:
- return false
- cursor1.close()
- cnx1.close()
- ############## SQL#########################
- from Functions import *
- import pymysql
- import urllib.request, json
- cnx = pymysql.connect(user='root', password='Ettema128611', host='127.0.0.1', database='rossmann')
- cursor = cnx.cursor()
- longadress_list=[]
- cursor.execute("SELECT Adresse, kette FROM filialen")
- cnx.commit()
- for adress in cursor.fetchall():
- longadress_list.append(str(adress))
- for i in (longadress_list):
- words = i.replace("(", "")
- words1= words.replace("'","")
- words2= words1.replace(")","").split(",")
- words3=words2[1].split(" ")
- checkandinsert_comp(words2[2].strip())
- checkandinsert_zipcode((str(words3[1].strip())))
- checkandinsert_city((str(words3[2].strip())))
- checkandinsert_address(str(words2[0]), str(words3[1].strip()), words3[2].strip(), words2[2].strip())
- ###################JSON#####################3
- from Functions import *
- import urllib.request, json
- data = json.load(open('rossmann.json'))
- for i in range(len(data)):
- split_original_zipcode=((data[i]['stadt'].split(" ")))
- print()
- checkandinsert_zipcode(split_original_zipcode[0].strip())
- checkandinsert_city(split_original_zipcode[1].strip())
- checkandinsert_comp(((data[i]['kette'])))
- checkandinsert_address((data[i]['strasse']), split_original_zipcode[0].strip(),split_original_zipcode[1].strip(), (data[i]['kette']))
- ############################GUI################################
- from tkinter import *
- from Functions import *
- class Application:
- def __init__(self, master): #"master" represents the parent window, where the entry widget should be placed.
- self.master = master
- master.title("Competitors for Normal A/S")
- #Caption
- self.label = Label(master, text="Entries for competitors for normal A/S", font=("",10))
- self.label.grid(row = 0, column = 0, columnspan = 2, sticky = W)
- #Shut down button
- self.close_button = Button(master, text="Close", command=master.quit)
- self.close_button.grid(row = 8, column = 5, columnspan = 2)
- #Compeptitor entry and label
- self.comp_lbl = Label(master, text = "Competitors name")
- self.comp_lbl.grid(row = 1, column = 0, columnspan = 4, sticky = W)
- self.entry_comp= Entry(master,width=50)
- self.entry_comp.grid(row=1,column=4,sticky=W)
- #Adress entry and label
- self.adress_lbl = Label(master, text = "Address")
- self.adress_lbl.grid(row = 2, column = 0, columnspan = 4, sticky = W)
- self.entry_adress= Entry(master,width=50)
- self.entry_adress.grid(row=2,column=4,sticky=W)
- #Zipcode entry and label
- self.zipcode_lbl = Label(master, text = "Zipcode")
- self.zipcode_lbl.grid(row = 3, column = 0, columnspan = 4, sticky = W)
- self.entry_zipcode= Entry(master,width=50)
- self.entry_zipcode.grid(row=3,column=4,sticky=W)
- self.zipcode_lbl = Label(master, text = "City")
- self.zipcode_lbl.grid(row = 4, column = 0, columnspan = 4, sticky = W)
- self.entry_city= Entry(master,width=50)
- self.entry_city.grid(row=4,column=4,sticky=W)
- #Entry and label for "Entry Succesfull"
- self.label1 = Label(master, text = "Was the entry succesfull?")
- self.label1.grid(row = 5, column = 0, columnspan = 4, sticky = W)
- self.entry_succesfull= Entry(master,width=50)
- self.entry_succesfull.grid(row=5,column=4,sticky=W)
- #Add to database button
- self.search_button = Button(master, text="Add to database", command=self.Ad_to_database)
- self.search_button.grid(row = 6, column = 3, columnspan =2 , sticky = E)
- #function that bind esc to exit
- self.master.bind('<Escape>', self.esc)
- def esc(self,empty):
- self.master.quit()
- def Ad_to_database(self):
- self.entry_succesfull.configure(bg = "white")
- self.entry_succesfull.delete(0,END)
- message_succes= "The information has entered the database"
- message_already="The information was all ready in the database"
- message_error = "Insufficient information, please try again"
- self.entry_succesfull.delete(0,END)
- if len(self.entry_adress.get()) <=1 and len(self.entry_zipcode.get())<=1 and len(self.entry_comp.get())<=0:
- self.entry_succesfull.insert(0,message_error)
- self.entry_succesfull.configure(bg = "red")
- else:
- if checkandinsert_comp(str(self.entry_comp.get()))== false and checkandinsert_zipcode(str(self.entry_zipcode.get()))== false and checkandinsert_address(str(self.entry_adress.get()), str(self.entry_zipcode.get()), str(self.entry_comp.get())) ==false:
- self.entry_succesfull.delete(0,END)
- self.entry_succesfull.insert(0,message_already)
- self.entry_succesfull.configure(bg = "yellow")
- self.clear_all_entries()
- else:
- self.entry_succesfull.insert(0,message_succes)
- self.entry_succesfull.configure(bg = "green")
- checkandinsert_comp(str(self.entry_comp.get()))
- checkandinsert_zipcode(str(self.entry_zipcode.get()))
- checkandinsert_city(str(self.entry_city.get()))
- checkandinsert_address(str(self.entry_adress.get()), str(self.entry_zipcode.get()), str(self.entry_comp.get()))
- self.clear_all_entries()
- def clear_all_entries(self):
- self.entry_adress.delete(0,END)
- self.entry_zipcode.delete(0,END)
- self.entry_comp.delete(0,END)
- root = Tk()
- root.title("Kosmetik and more stores in Germany")
- root.geometry("670x200")
- my_gui = Application(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement