3 Commits
Author SHA1 Message Date
Schrom01 4672ccef6e lot of changes 2026-03-10 09:13:04 +01:00
Schrom01 450b58e1e9 unique image filename for same addresses with different ids 2025-06-11 21:46:07 +02:00
Schrom01 7234a330a8 qr-codes with individual data 2025-06-11 21:42:27 +02:00
2 changed files with 33 additions and 31 deletions
+32 -30
View File
@@ -1,6 +1,8 @@
import tkinter import tkinter
import threading import threading
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
plt.switch_backend("Agg") # Set the backend dynamically
from urllib.parse import urlencode, quote_plus
import selenium.webdriver.firefox.service import selenium.webdriver.firefox.service
import webdriver_manager.chrome import webdriver_manager.chrome
@@ -24,11 +26,11 @@ import requests
import statistics import statistics
from webdriver_manager.firefox import GeckoDriverManager from webdriver_manager.firefox import GeckoDriverManager
DropDownLabels = ["Street: ", "Number: ", "Postal code: ", "City: ", "coordinate X", "coordinate Y", "Sonnendach URL: ", "Suitability:", "Image Filename: ", "PV Production 75", "Value Electricity production", "Roof area", "existing PV Production Power", "existing PV Production begining of operation"] DropDownLabels = ["Street: ", "Number: ", "Postal code: ", "City: ", "coordinate X", "coordinate Y", "Sonnendach URL: ", "Suitability:", "Image Filename: ", "PV Production 75", "Value Electricity production", "Roof area", "existing PV Production Power", "existing PV Production begining of operation","id", "firstname", "lastname"]
file_split_char = "," file_split_char = ";"
minRoofSize = 2 minRoofSize = 2
minSuitability = 3 minSuitability = 3
electricityPrice = 0.198 electricityPrice = 0.09976
electricityUsageFactor = 0.75 electricityUsageFactor = 0.75
OptionList = [] OptionList = []
exit = False exit = False
@@ -185,7 +187,7 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
for month_count in range(12): for month_count in range(12):
barChartData[month_count] = barChartData[month_count] + float( barChartData[month_count] = barChartData[month_count] + float(
roof['attributes']['monats_ertrag'][month_count]) * float( roof['attributes']['monats_ertrag'][month_count]) * float(
roof['attributes']['flaeche']) * electricityPrice roof['attributes']['flaeche']) * electricityPrice * 0.75
sumEnergyRoofs = sumEnergyRoofs + energy sumEnergyRoofs = sumEnergyRoofs + energy
sumRoofArea = sumRoofArea + float(roof['attributes']['flaeche']) sumRoofArea = sumRoofArea + float(roof['attributes']['flaeche'])
suitabilities.append(int(roof['attributes']['klasse'])) suitabilities.append(int(roof['attributes']['klasse']))
@@ -233,7 +235,7 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
roof_has_solarpanel = False roof_has_solarpanel = False
if(found and createImages.get() > 0 and roof_is_suitable and (not roof_has_solarpanel)): if(found and createImages.get() > 0 and roof_is_suitable and (not roof_has_solarpanel)):
image_filename = address_string + ".png" image_filename = adress[columnIndexes[14]] + " " + address_string + ".png"
barchart_color = "" barchart_color = ""
if(suitability == 1): if(suitability == 1):
@@ -247,8 +249,10 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
elif(suitability == 5): elif(suitability == 5):
barchart_color = "#a80000" barchart_color = "#a80000"
qr_url = "https://nexs.ch"
create_images(address_string, driver, image_filename, image_folder_map, image_folder_production, image_folder_qrcode, image_folder_barcharts, create_images(address_string, driver, image_filename, image_folder_map, image_folder_production, image_folder_qrcode, image_folder_barcharts,
url, barChartMonth, barChartData, barchart_color) url, barChartMonth, barChartData, barchart_color, qr_url)
else: else:
image_filename = "not-created" image_filename = "not-created"
@@ -265,14 +269,6 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
print("Process is running since %d years %d months %d days %d hours %d minutes %d seconds" % ( print("Process is running since %d years %d months %d days %d hours %d minutes %d seconds" % (
timediff.years, timediff.months, timediff.days, timediff.hours, timediff.minutes, timediff.seconds)) timediff.years, timediff.months, timediff.days, timediff.hours, timediff.minutes, timediff.seconds))
# if(found):
# street = adress[columnIndexes[0]] + " " + adress[columnIndexes[1]]
# plz = adress[columnIndexes[2]]
# city = adress[columnIndexes[3]]
# create_Partner_in_dolibarr(street, plz, city, coordinates, sumEnergyRoofs, sumRoofArea, suitability, featureId, url, response_all_roofs_decoded)
if(stopThread == True): if(stopThread == True):
print("closing Thread") print("closing Thread")
@@ -352,21 +348,26 @@ def create_roof_info(roofs):
info_text = info_text + str(i + 1) + ". Fläche\n" + "Potenzielle Energie: " + str(roofs[i]['attributes']['gstrahlung']*0.2*0.8) + "\nFläche: " + str(roofs[i]['attributes']['flaeche']) + "\nEignung: " + str(roofs[i]['attributes']['klasse']) + " (" + str(roofs[i]['attributes']['klasse_text']).split("##")[0] + ")\n\n" info_text = info_text + str(i + 1) + ". Fläche\n" + "Potenzielle Energie: " + str(roofs[i]['attributes']['gstrahlung']*0.2*0.8) + "\nFläche: " + str(roofs[i]['attributes']['flaeche']) + "\nEignung: " + str(roofs[i]['attributes']['klasse']) + " (" + str(roofs[i]['attributes']['klasse_text']).split("##")[0] + ")\n\n"
return info_text return info_text
def create_images(address_string, driver, image_filename, image_folder_map, image_folder_production, image_folder_qrcode, image_folder_barcharts, url, barChartMonth, barChartData, barchart_color): def create_images(address_string, driver, image_filename, image_folder_map, image_folder_production, image_folder_qrcode, image_folder_barcharts, url, barChartMonth, barChartData, barchart_color, qr_url):
driver.get(url) driver.get(url)
time.sleep(2) time.sleep(2)
# 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(qr_url)
qr.make(fit=True) # qr.make(fit=True)
qr.make_image(fill='black', back_color='white').save(image_folder_qrcode + image_filename) # qr.make_image(fill='black', back_color='white').save(image_folder_qrcode + image_filename)
# 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);""")
# Marker entfernen
# driver.execute_script("""var l = document.getElementsByClassName("marker ga-crosshair")[0];
# l.parentNode.removeChild(l);""")
except: except:
pass pass
@@ -379,12 +380,13 @@ def create_images(address_string, driver, image_filename, image_folder_map, imag
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) + ")") mapElement.screenshot(image_folder_map + image_filename)
time.sleep(1) # driver.execute_script("window.scrollTo(0, " + str(y) + ")")
driver.save_screenshot(image_folder_map + image_filename) # time.sleep(1)
time.sleep(0.2) # driver.save_screenshot(image_folder_map + image_filename)
Image.open(image_folder_map + image_filename).crop(area).save( # time.sleep(0.2)
image_folder_map + image_filename) # Image.open(image_folder_map + image_filename).crop(area).save(
# image_folder_map + image_filename)
# Create Screenshot of Chart # Create Screenshot of Chart
# try: # try:
@@ -434,7 +436,7 @@ def create_images(address_string, driver, image_filename, image_folder_map, imag
# plt.xlim(barChartMonth[0], barChartMonth[-1]) # plt.xlim(barChartMonth[0], barChartMonth[-1])
plt.savefig(f"{image_folder_barcharts}{image_filename}", bbox_inches='tight') plt.savefig(f"{image_folder_barcharts}{image_filename}", bbox_inches='tight')
plt.close('all')
except: except:
pass pass
@@ -464,10 +466,10 @@ def createFrameFileColums(headers):
frameFileColums1.grid(row=2, column=1, padx=10, pady=3) frameFileColums1.grid(row=2, column=1, padx=10, pady=3)
for i in range(len(DropDownLabels)): for i in range(len(DropDownLabels)):
exec("text" + str(i+1) + " = tkinter.Label(frameFileColums1, text=\"" + DropDownLabels[i] + "\")") text = tkinter.Label(frameFileColums1, text=DropDownLabels[i])
exec("text" + str(i+1) + ".grid(row=" + str(i+1) + ", column=1, padx=10, pady=3)") text.grid(row=i + 1, column=1, padx=10, pady=3)
exec("dropdown" + str(i+1) + " = tkinter.OptionMenu(frameFileColums1, variablesDropdown[" + str(i) + "], *OptionList)") dropdown = tkinter.OptionMenu(frameFileColums1, variablesDropdown[i], *OptionList)
exec("dropdown" + str(i+1) + ".grid(row=" + str(i+1) + ", column=2, padx=10, pady=3)") dropdown.grid(row=i+1, column=2, padx=10, pady=3)
def getColumnIndex(): def getColumnIndex():
global OptionList global OptionList
+1 -1
View File
@@ -2,7 +2,7 @@
import json import json
import requests import requests
search_string = "Toggenburgstrasse 31 8245 Feuerthalen" search_string = "Blankweg 46 3072 Ostermundigen"
#Address to coordinates #Address to coordinates
params={ params={