parent
427f21e41d
commit
20100db9b8
155
Main.py
155
Main.py
|
@ -12,7 +12,7 @@ import time
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
OptionList = []
|
||||||
exit = False
|
exit = False
|
||||||
stopThread = False
|
stopThread = False
|
||||||
filename_adresslist = ""
|
filename_adresslist = ""
|
||||||
|
@ -22,16 +22,30 @@ s = Service(ChromeDriverManager().install())
|
||||||
driver = webdriver.Chrome(service=s)
|
driver = webdriver.Chrome(service=s)
|
||||||
driver.minimize_window()
|
driver.minimize_window()
|
||||||
outputtext = "Welcome to application Sonnendach\n"
|
outputtext = "Welcome to application Sonnendach\n"
|
||||||
|
file_split_char = ","
|
||||||
|
|
||||||
|
|
||||||
def search_adresses(adress_list, filename_adresslist, driver):
|
def search_adresses(adress_list, filename_adresslist, driver):
|
||||||
file_split_char = ","
|
global file_split_char
|
||||||
global exit
|
global stopThread
|
||||||
|
columnIndex1 = getColumnIndex(variabledropdown1.get())
|
||||||
|
columnIndex2 = getColumnIndex(variabledropdown2.get())
|
||||||
|
columnIndex3 = getColumnIndex(variabledropdown3.get())
|
||||||
|
columnIndex4 = getColumnIndex(variabledropdown4.get())
|
||||||
|
columnIndex5 = getColumnIndex(variabledropdown5.get())
|
||||||
|
columnIndex6 = getColumnIndex(variabledropdown6.get())
|
||||||
|
columnIndex7 = getColumnIndex(variabledropdown7.get())
|
||||||
|
columnIndex8 = getColumnIndex(variabledropdown8.get())
|
||||||
|
columnIndex9 = getColumnIndex(variabledropdown9.get())
|
||||||
|
columnIndex10 = getColumnIndex(variabledropdown10.get())
|
||||||
|
columnIndex11 = getColumnIndex(variabledropdown11.get())
|
||||||
|
|
||||||
for i in range(len(adress_list)):
|
for i in range(len(adress_list)):
|
||||||
line = adress_list[i]
|
line = adress_list[i]
|
||||||
adress = line.split(file_split_char)
|
adress = line.split(file_split_char)
|
||||||
if((line != adress_list[0]) & ((adress[20][0:11] != "screenshots"))):
|
if((line != adress_list[0]) & ((adress[20][0:11] != "screenshots"))):
|
||||||
print(adress)
|
print(adress)
|
||||||
search_string = adress[15] + " " + adress[3] + " " + adress[11] + " " + adress[13]
|
search_string = adress[columnIndex1] + " " + adress[columnIndex2] + " " + adress[columnIndex3] + " " + adress[columnIndex4]
|
||||||
search_bar = driver.find_element(By.ID, "searchTypeahead1")
|
search_bar = driver.find_element(By.ID, "searchTypeahead1")
|
||||||
search_bar.send_keys(Keys.CONTROL + "a")
|
search_bar.send_keys(Keys.CONTROL + "a")
|
||||||
search_bar.send_keys(Keys.DELETE)
|
search_bar.send_keys(Keys.DELETE)
|
||||||
|
@ -44,7 +58,7 @@ def search_adresses(adress_list, filename_adresslist, driver):
|
||||||
if(suggestion.text == search_string):
|
if(suggestion.text == search_string):
|
||||||
found = True
|
found = True
|
||||||
suggestion.click()
|
suggestion.click()
|
||||||
driver.implicitly_wait(120)
|
driver.implicitly_wait(5)
|
||||||
break
|
break
|
||||||
|
|
||||||
if(found):
|
if(found):
|
||||||
|
@ -54,9 +68,9 @@ def search_adresses(adress_list, filename_adresslist, driver):
|
||||||
eignung = driver.find_element(By.ID, "eignung")
|
eignung = driver.find_element(By.ID, "eignung")
|
||||||
image_filename = "screenshots/" + eignung.text + " - " + search_string + ".png"
|
image_filename = "screenshots/" + eignung.text + " - " + search_string + ".png"
|
||||||
|
|
||||||
adress[18] = url
|
adress[columnIndex5] = url
|
||||||
adress[19] = eignung.text
|
adress[columnIndex6] = eignung.text
|
||||||
adress[20] = image_filename
|
adress[columnIndex7] = image_filename
|
||||||
|
|
||||||
adress_file = open(filename_adresslist, "w")
|
adress_file = open(filename_adresslist, "w")
|
||||||
new_line_string = ""
|
new_line_string = ""
|
||||||
|
@ -88,9 +102,8 @@ def search_adresses(adress_list, filename_adresslist, driver):
|
||||||
print(image_filename + " was saved.")
|
print(image_filename + " was saved.")
|
||||||
else:
|
else:
|
||||||
print("not found: " + search_string)
|
print("not found: " + search_string)
|
||||||
|
|
||||||
if(stopThread == True):
|
if(stopThread == True):
|
||||||
print("Exit")
|
print("closing Thread")
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,6 +119,57 @@ def read_adresslist(filename_adresslist):
|
||||||
returnvalues.append(False)
|
returnvalues.append(False)
|
||||||
return returnvalues
|
return returnvalues
|
||||||
|
|
||||||
|
def createFrameFileColums(headers):
|
||||||
|
global OptionList
|
||||||
|
for header in headers:
|
||||||
|
OptionList.append(header)
|
||||||
|
desctext = tkinter.Label(frameFileColums, text="Please type in Header of Columns")
|
||||||
|
desctext.grid(row=1, column=1, padx=10, pady=3)
|
||||||
|
frameFileColums1 = tkinter.Frame(frameFileColums)
|
||||||
|
frameFileColums1.grid(row=2, column=1, padx=10, pady=3)
|
||||||
|
|
||||||
|
text1 = tkinter.Label(frameFileColums1, text="Street: ")
|
||||||
|
text1.grid(row=1, column=1, padx=10, pady=3)
|
||||||
|
dropdown1 = tkinter.OptionMenu(frameFileColums1, variabledropdown1, *OptionList)
|
||||||
|
dropdown1.grid(row=1, column=2, padx=10, pady=3)
|
||||||
|
|
||||||
|
text2 = tkinter.Label(frameFileColums1, text="Number: ")
|
||||||
|
text2.grid(row=2, column=1, padx=10, pady=3)
|
||||||
|
dropdown2 = tkinter.OptionMenu(frameFileColums1, variabledropdown2, *OptionList)
|
||||||
|
dropdown2.grid(row=2, column=2, padx=10, pady=3)
|
||||||
|
|
||||||
|
text3 = tkinter.Label(frameFileColums1, text="Postal code: ")
|
||||||
|
text3.grid(row=3, column=1, padx=10, pady=3)
|
||||||
|
dropdown3 = tkinter.OptionMenu(frameFileColums1, variabledropdown3, *OptionList)
|
||||||
|
dropdown3.grid(row=3, column=2, padx=10, pady=3)
|
||||||
|
|
||||||
|
text4 = tkinter.Label(frameFileColums1, text="City: ")
|
||||||
|
text4.grid(row=4, column=1, padx=10, pady=3)
|
||||||
|
dropdown4 = tkinter.OptionMenu(frameFileColums1, variabledropdown4, *OptionList)
|
||||||
|
dropdown4.grid(row=4, column=2, padx=10, pady=3)
|
||||||
|
|
||||||
|
text5 = tkinter.Label(frameFileColums1, text="Sonnendach URL: ")
|
||||||
|
text5.grid(row=5, column=1, padx=10, pady=3)
|
||||||
|
dropdown5 = tkinter.OptionMenu(frameFileColums1, variabledropdown5, *OptionList)
|
||||||
|
dropdown5.grid(row=5, column=2, padx=10, pady=3)
|
||||||
|
|
||||||
|
text6 = tkinter.Label(frameFileColums1, text="Eignung")
|
||||||
|
text6.grid(row=6, column=1, padx=10, pady=3)
|
||||||
|
dropdown6 = tkinter.OptionMenu(frameFileColums1, variabledropdown6, *OptionList)
|
||||||
|
dropdown6.grid(row=6, column=2, padx=10, pady=3)
|
||||||
|
|
||||||
|
text7 = tkinter.Label(frameFileColums1, text="Screenshot Filename: ")
|
||||||
|
text7.grid(row=7, column=1, padx=10, pady=3)
|
||||||
|
dropdown7 = tkinter.OptionMenu(frameFileColums1, variabledropdown7, *OptionList)
|
||||||
|
dropdown7.grid(row=7, column=2, padx=10, pady=3)
|
||||||
|
|
||||||
|
|
||||||
|
def getColumnIndex(header):
|
||||||
|
global OptionList
|
||||||
|
for i in range(len(OptionList)):
|
||||||
|
if(OptionList[i] == header):
|
||||||
|
return i
|
||||||
|
|
||||||
def command():
|
def command():
|
||||||
global exit
|
global exit
|
||||||
global stopThread
|
global stopThread
|
||||||
|
@ -115,56 +179,67 @@ def command():
|
||||||
global filename_adresslist
|
global filename_adresslist
|
||||||
global outputtext
|
global outputtext
|
||||||
global thread_search_adresses
|
global thread_search_adresses
|
||||||
|
global file_split_char
|
||||||
if(exit):
|
if(exit):
|
||||||
|
print("Command Exit received")
|
||||||
stopThread = True
|
stopThread = True
|
||||||
outputtext = outputtext + "Application will stop" + "\n"
|
|
||||||
text1.config(text=outputtext)
|
|
||||||
try:
|
try:
|
||||||
thread_search_adresses.join()
|
thread_search_adresses.join()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
print("Thread is closed")
|
||||||
root.quit()
|
root.quit()
|
||||||
|
print("Application is closed")
|
||||||
driver.quit()
|
driver.quit()
|
||||||
|
print("Webdriver is closed")
|
||||||
elif(step == 0):
|
elif(step == 0):
|
||||||
#Schritt 1
|
#Schritt 1
|
||||||
filename_adresslist = filedialog.askopenfilename()
|
filename_adresslist = filedialog.askopenfilename()
|
||||||
outputtext = outputtext + "Reading File " + filename_adresslist + "\n"
|
outputtext = outputtext + "Searching File " + filename_adresslist + "\n"
|
||||||
text1.config(text=outputtext)
|
mainText.config(text=outputtext)
|
||||||
adress_list_result = read_adresslist(filename_adresslist)
|
adress_list_result = read_adresslist(filename_adresslist)
|
||||||
if(adress_list_result):
|
if(adress_list_result):
|
||||||
adresslist = adress_list_result[1]
|
adresslist = adress_list_result[1]
|
||||||
outputtext = outputtext + "Reading file " + filename_adresslist + " done." + "\n"
|
outputtext = outputtext + "File " + filename_adresslist + " found." + "\n"
|
||||||
text1.config(text=outputtext)
|
mainText.config(text=outputtext)
|
||||||
button1.config(text="open Webbrowser")
|
button1.config(text="read file")
|
||||||
|
createFrameFileColums(adresslist[0].split(file_split_char))
|
||||||
|
frameFileColums.grid(row=2, column=1)
|
||||||
step += 1
|
step += 1
|
||||||
else:
|
else:
|
||||||
outputtext = outputtext + "Reading file " + filename_adresslist + " failed." + "\n"
|
outputtext = outputtext + "File " + filename_adresslist + " not found." + "\n"
|
||||||
text1.config(text=outputtext)
|
mainText.config(text=outputtext)
|
||||||
exit = True
|
exit = True
|
||||||
button1.grid_remove()
|
button1.grid_remove()
|
||||||
elif(step == 1):
|
elif (step == 1):
|
||||||
|
outputtext = outputtext + "Reading File " + filename_adresslist + " done." + "\n"
|
||||||
|
mainText.config(text=outputtext)
|
||||||
|
frameFileColums.grid_remove()
|
||||||
|
button1.config(text="open Webbrowser")
|
||||||
|
step += 1
|
||||||
|
elif(step == 2):
|
||||||
# Schritt 2
|
# Schritt 2
|
||||||
outputtext = outputtext + "Website is opening" + "\n"
|
outputtext = outputtext + "Website is opening" + "\n"
|
||||||
text1.config(text=outputtext)
|
mainText.config(text=outputtext)
|
||||||
try:
|
try:
|
||||||
driver.maximize_window()
|
driver.maximize_window()
|
||||||
driver.get("https://www.uvek-gis.admin.ch/BFE/sonnendach/")
|
driver.get("https://www.uvek-gis.admin.ch/BFE/sonnendach/")
|
||||||
driver.implicitly_wait(20)
|
driver.implicitly_wait(20)
|
||||||
outputtext = outputtext + "opening website was done.\nPrepare the browser window to create screenshots." + "\n"
|
outputtext = outputtext + "opening website was done.\nPrepare the browser window to create screenshots." + "\n"
|
||||||
text1.config(text=outputtext)
|
mainText.config(text=outputtext)
|
||||||
button1.config(text="start process")
|
button1.config(text="start process")
|
||||||
step += 1
|
step += 1
|
||||||
except:
|
except:
|
||||||
outputtext = outputtext + "opening website failed" + "\n"
|
outputtext = outputtext + "opening website failed" + "\n"
|
||||||
text1.config(text=outputtext)
|
mainText.config(text=outputtext)
|
||||||
exit = True
|
exit = True
|
||||||
button1.grid_remove()
|
button1.grid_remove()
|
||||||
elif(step == 2):
|
elif(step == 3):
|
||||||
thread_search_adresses = threading.Thread(target=search_adresses, args=(adresslist, filename_adresslist, driver))
|
thread_search_adresses = threading.Thread(target=search_adresses, args=(adresslist, filename_adresslist, driver))
|
||||||
thread_search_adresses.start()
|
thread_search_adresses.start()
|
||||||
#search_adresses(adresslist, filename_adresslist, driver)
|
print("Thread started")
|
||||||
outputtext = outputtext + "process running." + "\n"
|
outputtext = outputtext + "process running." + "\n"
|
||||||
text1.config(text=outputtext)
|
mainText.config(text=outputtext)
|
||||||
button1.grid_remove()
|
button1.grid_remove()
|
||||||
exit = True
|
exit = True
|
||||||
|
|
||||||
|
@ -178,12 +253,28 @@ def command_exit():
|
||||||
|
|
||||||
root = tkinter.Tk()
|
root = tkinter.Tk()
|
||||||
root.wm_title("Sonnendach")
|
root.wm_title("Sonnendach")
|
||||||
text1 = tkinter.Label(root, text=outputtext, width=80, height=30)
|
mainText = tkinter.Label(root, text=outputtext, width=80)
|
||||||
text1.grid(row=1, column=1, padx=10, pady=3)
|
mainText.grid(row=1, column=1, padx=10, pady=3)
|
||||||
button1 = tkinter.Button(root, text="Select Adresslist file", command=command, width=20, height=2, bg="#FCCA03")
|
|
||||||
button1.grid(row=2, column=1, padx=10, pady=3)
|
frameFileColums = tkinter.Frame(root)
|
||||||
button2 = tkinter.Button(root, text="EXIT", command=command_exit, width=20, height=2, bg="#FCCA03")
|
variabledropdown1 = tkinter.StringVar(root)
|
||||||
button2.grid(row=2, column=2, padx=10, pady=3)
|
variabledropdown2 = tkinter.StringVar(root)
|
||||||
|
variabledropdown3 = tkinter.StringVar(root)
|
||||||
|
variabledropdown4 = tkinter.StringVar(root)
|
||||||
|
variabledropdown5 = tkinter.StringVar(root)
|
||||||
|
variabledropdown6 = tkinter.StringVar(root)
|
||||||
|
variabledropdown7 = tkinter.StringVar(root)
|
||||||
|
variabledropdown8 = tkinter.StringVar(root)
|
||||||
|
variabledropdown9 = tkinter.StringVar(root)
|
||||||
|
variabledropdown10 = tkinter.StringVar(root)
|
||||||
|
variabledropdown11 = tkinter.StringVar(root)
|
||||||
|
|
||||||
|
frameButtons = tkinter.Frame(root)
|
||||||
|
frameButtons.grid(row=3, column=1)
|
||||||
|
button1 = tkinter.Button(frameButtons, text="Select Adresslist file", command=command, width=20, height=2, bg="#FCCA03")
|
||||||
|
button1.grid(row=3, column=1, padx=10, pady=3)
|
||||||
|
button2 = tkinter.Button(frameButtons, text="EXIT", command=command_exit, width=20, height=2, bg="#FCCA03")
|
||||||
|
button2.grid(row=3, column=2, padx=10, pady=3)
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue