making_image_jobs_optional #6
			
				
			
		
		
		
	
							
								
								
									
										111
									
								
								Sonnendach.py
								
								
								
								
							
							
						
						
									
										111
									
								
								Sonnendach.py
								
								
								
								
							| 
						 | 
					@ -12,7 +12,8 @@ from tkinter import filedialog
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
from selenium.webdriver.common.action_chains import ActionChains
 | 
					from selenium.webdriver.common.action_chains import ActionChains
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DropDownLabels = ["Street: ", "Number: ", "Postal code: ", "City: ", "Sonnendach URL: ", "Suitability", "Image Filename Map: ", "Image Filename Production: ", "Image Filename qrcode: ", "PV Production 50", "PV Production 75", "PV Production 100", "Value Electricity production"]
 | 
					create_images = True
 | 
				
			||||||
 | 
					DropDownLabels = ["Street: ", "Number: ", "Postal code: ", "City: ", "Sonnendach URL: ", "Suitability", "Image Filename Map: ", "Image Filename Production: ", "Image Filename qrcode: ", "PV Production 50", "PV Production 75", "PV Production 100", "Value Electricity production", "Roof area"]
 | 
				
			||||||
file_split_char = ","
 | 
					file_split_char = ","
 | 
				
			||||||
OptionList = []
 | 
					OptionList = []
 | 
				
			||||||
exit = False
 | 
					exit = False
 | 
				
			||||||
| 
						 | 
					@ -41,8 +42,9 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
 | 
				
			||||||
    if (not os.path.exists("qrcodes")):
 | 
					    if (not os.path.exists("qrcodes")):
 | 
				
			||||||
        os.makedirs("qrcodes", exist_ok=False)
 | 
					        os.makedirs("qrcodes", exist_ok=False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    address_count = len(adress_list)
 | 
				
			||||||
    #Search for each adress in the list and create screenshots and qrcodes
 | 
					    #Search for each adress in the list and create screenshots and qrcodes
 | 
				
			||||||
    for i in range(len(adress_list)):
 | 
					    for i in range(address_count):
 | 
				
			||||||
        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[columnIndexes[4]] == "") & (len(adress[columnIndexes[0]]) > 0) & (len(adress[columnIndexes[1]]) > 0) & (len(adress[columnIndexes[2]]) > 0) & (len(adress[columnIndexes[3]]) > 0)):
 | 
					        if((line != adress_list[0]) & (adress[columnIndexes[4]] == "") & (len(adress[columnIndexes[0]]) > 0) & (len(adress[columnIndexes[1]]) > 0) & (len(adress[columnIndexes[2]]) > 0) & (len(adress[columnIndexes[3]]) > 0)):
 | 
				
			||||||
| 
						 | 
					@ -71,67 +73,75 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
 | 
				
			||||||
                pv_Production75 = driver.find_element(By.ID, "pv75").text.replace("'", "")
 | 
					                pv_Production75 = driver.find_element(By.ID, "pv75").text.replace("'", "")
 | 
				
			||||||
                pv_Production100 = driver.find_element(By.ID, "pv100").text.replace("'", "")
 | 
					                pv_Production100 = driver.find_element(By.ID, "pv100").text.replace("'", "")
 | 
				
			||||||
                value_electricity_production = driver.find_elements(By.XPATH, "//h2[@id='TitelSolarstrom']//strong")[2].text.replace("'", "").replace(" Franken", "")
 | 
					                value_electricity_production = driver.find_elements(By.XPATH, "//h2[@id='TitelSolarstrom']//strong")[2].text.replace("'", "").replace(" Franken", "")
 | 
				
			||||||
 | 
					                roof_area = driver.find_element(By.ID, "areaOutput")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if(create_images):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                image_filename = suitability + " - " + search_string
 | 
					                    image_filename = suitability + " - " + search_string
 | 
				
			||||||
                image_folder_map = "screenshots/"
 | 
					                    image_folder_map = "screenshots/"
 | 
				
			||||||
                image_filename_map = image_filename + " map" + ".png"
 | 
					                    image_filename_map = image_filename + " map" + ".png"
 | 
				
			||||||
                image_folder_production = "screenshots/"
 | 
					                    image_folder_production = "screenshots/"
 | 
				
			||||||
                image_filename_production = image_filename + " production" + ".png"
 | 
					                    image_filename_production = image_filename + " production" + ".png"
 | 
				
			||||||
                image_folder_qrcode = "qrcodes/"
 | 
					                    image_folder_qrcode = "qrcodes/"
 | 
				
			||||||
                image_filename_qrcode = image_filename + " qrcode" + ".png"
 | 
					                    image_filename_qrcode = image_filename + " qrcode" + ".png"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                # Create QR-Code
 | 
					                    # Create QR-Code
 | 
				
			||||||
                qr = qrcode.QRCode(version=1, box_size=10, border=5)
 | 
					                    qr = qrcode.QRCode(version=1, box_size=10, border=5)
 | 
				
			||||||
                qr.add_data(url)
 | 
					                    qr.add_data(url)
 | 
				
			||||||
                qr.make(fit=True)
 | 
					                    qr.make(fit=True)
 | 
				
			||||||
                qr.make_image(fill='black', back_color='white').save(image_folder_qrcode + image_filename_qrcode)
 | 
					                    qr.make_image(fill='black', back_color='white').save(image_folder_qrcode + image_filename_qrcode)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                # Create Screenshot of Map
 | 
					                    # Create Screenshot of Map
 | 
				
			||||||
                actions = ActionChains(driver)
 | 
					                    actions = ActionChains(driver)
 | 
				
			||||||
                try:
 | 
					                    try:
 | 
				
			||||||
                    driver.execute_script("""var l = document.getElementsByClassName("ol-zoom ol-unselectable ol-control")[0];
 | 
					                        driver.execute_script("""var l = document.getElementsByClassName("ol-zoom ol-unselectable ol-control")[0];
 | 
				
			||||||
                                               l.parentNode.removeChild(l);""")
 | 
					                                                   l.parentNode.removeChild(l);""")
 | 
				
			||||||
                except:
 | 
					                    except:
 | 
				
			||||||
                    pass
 | 
					                        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                mapElement = driver.find_element(By.XPATH,
 | 
					                    mapElement = driver.find_element(By.XPATH,
 | 
				
			||||||
                                                 "//div[@id='map']//div[@class='ol-viewport']")
 | 
					                                                     "//div[@id='map']//div[@class='ol-viewport']")
 | 
				
			||||||
                location = mapElement.location
 | 
					                    location = mapElement.location
 | 
				
			||||||
                size = mapElement.size
 | 
					                    size = mapElement.size
 | 
				
			||||||
                x = location["x"]
 | 
					 | 
				
			||||||
                y = location["y"]
 | 
					 | 
				
			||||||
                w = x + size["width"]
 | 
					 | 
				
			||||||
                h = size["height"]
 | 
					 | 
				
			||||||
                area = (x, 0, w, h)
 | 
					 | 
				
			||||||
                driver.execute_script("window.scrollTo(0, " + str(y) + ")")
 | 
					 | 
				
			||||||
                time.sleep(1)
 | 
					 | 
				
			||||||
                driver.save_screenshot(image_folder_map + image_filename_map)
 | 
					 | 
				
			||||||
                time.sleep(0.2)
 | 
					 | 
				
			||||||
                Image.open(image_folder_map + image_filename_map).crop(area).save(
 | 
					 | 
				
			||||||
                    image_folder_map + image_filename_map)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                # Create Screenshot of Chart
 | 
					 | 
				
			||||||
                try:
 | 
					 | 
				
			||||||
                    chartElement = driver.find_elements(By.XPATH, "//div[@id='chart']//*")[0]
 | 
					 | 
				
			||||||
                    location = chartElement.location
 | 
					 | 
				
			||||||
                    size = chartElement.size
 | 
					 | 
				
			||||||
                    x = location["x"]
 | 
					                    x = location["x"]
 | 
				
			||||||
                    y = location["y"]
 | 
					                    y = location["y"]
 | 
				
			||||||
                    w = x + size["width"]
 | 
					                    w = x + size["width"]
 | 
				
			||||||
                    h = size["height"]
 | 
					                    h = size["height"]
 | 
				
			||||||
                    area = (x, 0, w, h)
 | 
					                    area = (x, 0, w, h)
 | 
				
			||||||
                    driver.execute_script("window.scrollTo(0, " + str(y) + ")")
 | 
					                    driver.execute_script("window.scrollTo(0, " + str(y) + ")")
 | 
				
			||||||
 | 
					 | 
				
			||||||
                    time.sleep(1)
 | 
					                    time.sleep(1)
 | 
				
			||||||
                    driver.save_screenshot(image_folder_production + image_filename_production)
 | 
					                    driver.save_screenshot(image_folder_map + image_filename_map)
 | 
				
			||||||
                    time.sleep(0.2)
 | 
					                    time.sleep(0.2)
 | 
				
			||||||
                    Image.open(image_folder_production + image_filename_production).crop(area).save(
 | 
					                    Image.open(image_folder_map + image_filename_map).crop(area).save(
 | 
				
			||||||
                        image_folder_production + image_filename_production)
 | 
					                        image_folder_map + image_filename_map)
 | 
				
			||||||
                except:
 | 
					 | 
				
			||||||
                    image_filename_production = "not-found"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                print(image_filename_map + " was saved.")
 | 
					                    # Create Screenshot of Chart
 | 
				
			||||||
 | 
					                    try:
 | 
				
			||||||
 | 
					                        chartElement = driver.find_elements(By.XPATH, "//div[@id='chart']//*")[0]
 | 
				
			||||||
 | 
					                        location = chartElement.location
 | 
				
			||||||
 | 
					                        size = chartElement.size
 | 
				
			||||||
 | 
					                        x = location["x"]
 | 
				
			||||||
 | 
					                        y = location["y"]
 | 
				
			||||||
 | 
					                        w = x + size["width"]
 | 
				
			||||||
 | 
					                        h = size["height"]
 | 
				
			||||||
 | 
					                        area = (x, 0, w, h)
 | 
				
			||||||
 | 
					                        driver.execute_script("window.scrollTo(0, " + str(y) + ")")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        time.sleep(1)
 | 
				
			||||||
 | 
					                        driver.save_screenshot(image_folder_production + image_filename_production)
 | 
				
			||||||
 | 
					                        time.sleep(0.2)
 | 
				
			||||||
 | 
					                        Image.open(image_folder_production + image_filename_production).crop(area).save(
 | 
				
			||||||
 | 
					                            image_folder_production + image_filename_production)
 | 
				
			||||||
 | 
					                    except:
 | 
				
			||||||
 | 
					                        image_filename_production = "not-found"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                else:
 | 
				
			||||||
 | 
					                    image_filename_map = "not created"
 | 
				
			||||||
 | 
					                    image_filename_production = "not created"
 | 
				
			||||||
 | 
					                    image_filename_qrcode = "not created"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                print("saved Address: " + search_string)
 | 
				
			||||||
 | 
					                print("Address " + str(i) + " of " + str(address_count))
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                url = "not-found"
 | 
					                url = "not-found"
 | 
				
			||||||
                suitability = "not-found"
 | 
					                suitability = "not-found"
 | 
				
			||||||
| 
						 | 
					@ -142,6 +152,7 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
 | 
				
			||||||
                pv_Production75 = "not-found"
 | 
					                pv_Production75 = "not-found"
 | 
				
			||||||
                pv_Production100 = "not-found"
 | 
					                pv_Production100 = "not-found"
 | 
				
			||||||
                value_electricity_production = "not-found"
 | 
					                value_electricity_production = "not-found"
 | 
				
			||||||
 | 
					                roof_area = "not-found"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                print("not found: " + search_string)
 | 
					                print("not found: " + search_string)
 | 
				
			||||||
| 
						 | 
					@ -157,6 +168,7 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
 | 
				
			||||||
            adress[columnIndexes[10]] = pv_Production75
 | 
					            adress[columnIndexes[10]] = pv_Production75
 | 
				
			||||||
            adress[columnIndexes[11]] = pv_Production100
 | 
					            adress[columnIndexes[11]] = pv_Production100
 | 
				
			||||||
            adress[columnIndexes[12]] = value_electricity_production
 | 
					            adress[columnIndexes[12]] = value_electricity_production
 | 
				
			||||||
 | 
					            adress[columnIndexes[13]] = roof_area
 | 
				
			||||||
            adress_file = open(filename_adresslist, "w", encoding="utf-8")
 | 
					            adress_file = open(filename_adresslist, "w", encoding="utf-8")
 | 
				
			||||||
            new_line_string = ""
 | 
					            new_line_string = ""
 | 
				
			||||||
            for j in adress:
 | 
					            for j in adress:
 | 
				
			||||||
| 
						 | 
					@ -178,7 +190,6 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
 | 
				
			||||||
    print("closing Thread")
 | 
					    print("closing Thread")
 | 
				
			||||||
    return
 | 
					    return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
def read_adresslist(filename_adresslist):
 | 
					def read_adresslist(filename_adresslist):
 | 
				
			||||||
    returnvalues = []
 | 
					    returnvalues = []
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue