roof area

image optional
This commit is contained in:
schrom01 2022-11-05 14:26:59 +01:00
parent 394b19ce17
commit ebb72cb845
1 changed files with 61 additions and 50 deletions

View File

@ -12,7 +12,8 @@ from tkinter import filedialog
import time
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 = ","
OptionList = []
exit = False
@ -41,8 +42,9 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
if (not os.path.exists("qrcodes")):
os.makedirs("qrcodes", exist_ok=False)
address_count = len(adress_list)
#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]
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)):
@ -71,67 +73,75 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
pv_Production75 = driver.find_element(By.ID, "pv75").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", "")
roof_area = driver.find_element(By.ID, "areaOutput")
if(create_images):
image_filename = suitability + " - " + search_string
image_folder_map = "screenshots/"
image_filename_map = image_filename + " map" + ".png"
image_folder_production = "screenshots/"
image_filename_production = image_filename + " production" + ".png"
image_folder_qrcode = "qrcodes/"
image_filename_qrcode = image_filename + " qrcode" + ".png"
image_filename = suitability + " - " + search_string
image_folder_map = "screenshots/"
image_filename_map = image_filename + " map" + ".png"
image_folder_production = "screenshots/"
image_filename_production = image_filename + " production" + ".png"
image_folder_qrcode = "qrcodes/"
image_filename_qrcode = image_filename + " qrcode" + ".png"
# Create QR-Code
qr = qrcode.QRCode(version=1, box_size=10, border=5)
qr.add_data(url)
qr.make(fit=True)
qr.make_image(fill='black', back_color='white').save(image_folder_qrcode + image_filename_qrcode)
# Create QR-Code
qr = qrcode.QRCode(version=1, box_size=10, border=5)
qr.add_data(url)
qr.make(fit=True)
qr.make_image(fill='black', back_color='white').save(image_folder_qrcode + image_filename_qrcode)
# Create Screenshot of Map
actions = ActionChains(driver)
try:
driver.execute_script("""var l = document.getElementsByClassName("ol-zoom ol-unselectable ol-control")[0];
l.parentNode.removeChild(l);""")
except:
pass
# Create Screenshot of Map
actions = ActionChains(driver)
try:
driver.execute_script("""var l = document.getElementsByClassName("ol-zoom ol-unselectable ol-control")[0];
l.parentNode.removeChild(l);""")
except:
pass
mapElement = driver.find_element(By.XPATH,
"//div[@id='map']//div[@class='ol-viewport']")
location = mapElement.location
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
mapElement = driver.find_element(By.XPATH,
"//div[@id='map']//div[@class='ol-viewport']")
location = mapElement.location
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_production + image_filename_production)
driver.save_screenshot(image_folder_map + image_filename_map)
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"
Image.open(image_folder_map + image_filename_map).crop(area).save(
image_folder_map + image_filename_map)
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:
url = "not-found"
suitability = "not-found"
@ -142,6 +152,7 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
pv_Production75 = "not-found"
pv_Production100 = "not-found"
value_electricity_production = "not-found"
roof_area = "not-found"
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[11]] = pv_Production100
adress[columnIndexes[12]] = value_electricity_production
adress[columnIndexes[13]] = roof_area
adress_file = open(filename_adresslist, "w", encoding="utf-8")
new_line_string = ""
for j in adress:
@ -178,7 +190,6 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
print("closing Thread")
return
def read_adresslist(filename_adresslist):
returnvalues = []
try: