making_image_jobs_optional #6
|
@ -16,7 +16,7 @@ from selenium.webdriver.common.action_chains import ActionChains
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
DropDownLabels = ["Street: ", "Number: ", "Postal code: ", "City: ", "coordinate X", "coordinate Y", "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"]
|
DropDownLabels = ["Street: ", "Number: ", "Postal code: ", "City: ", "coordinate X", "coordinate Y", "Sonnendach URL: ", "Suitability:", "Image Filename: ", "PV Production 100", "Value Electricity production", "Roof area"]
|
||||||
file_split_char = ","
|
file_split_char = ","
|
||||||
OptionList = []
|
OptionList = []
|
||||||
exit = False
|
exit = False
|
||||||
|
@ -40,10 +40,15 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
|
||||||
global checkBoxCreateImages
|
global checkBoxCreateImages
|
||||||
|
|
||||||
#Create Direcotrys to save screenshots and qrcodes if they don't exist yet.
|
#Create Direcotrys to save screenshots and qrcodes if they don't exist yet.
|
||||||
if(not os.path.exists("screenshots")):
|
image_folder_map = "screenshots_map/"
|
||||||
os.makedirs("screenshots", exist_ok=False)
|
image_folder_production = "screenshots_production/"
|
||||||
if (not os.path.exists("qrcodes")):
|
image_folder_qrcode = "qrcodes/"
|
||||||
os.makedirs("qrcodes", exist_ok=False)
|
if(not os.path.exists(image_folder_map[:-1])):
|
||||||
|
os.makedirs(image_folder_map[:-1], exist_ok=False)
|
||||||
|
if(not os.path.exists(image_folder_production[:-1])):
|
||||||
|
os.makedirs(image_folder_production[:-1], exist_ok=False)
|
||||||
|
if (not os.path.exists(image_folder_qrcode[:-1])):
|
||||||
|
os.makedirs(image_folder_qrcode[:-1], exist_ok=False)
|
||||||
|
|
||||||
startTime = datetime.datetime.now()
|
startTime = datetime.datetime.now()
|
||||||
address_count = len(adress_list)
|
address_count = len(adress_list)
|
||||||
|
@ -51,8 +56,6 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
|
||||||
for i in range(address_count):
|
for i in range(address_count):
|
||||||
url = "not-found"
|
url = "not-found"
|
||||||
suitability = "not-found"
|
suitability = "not-found"
|
||||||
pv_Production50 = "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"
|
roof_area = "not-found"
|
||||||
|
@ -129,43 +132,34 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
|
||||||
response_all_roofs = requests.get('https://api3.geo.admin.ch/rest/services/api/MapServer/find',
|
response_all_roofs = requests.get('https://api3.geo.admin.ch/rest/services/api/MapServer/find',
|
||||||
params=params)
|
params=params)
|
||||||
response_all_roofs_decoded = json.loads(response_all_roofs.content.decode())['results']
|
response_all_roofs_decoded = json.loads(response_all_roofs.content.decode())['results']
|
||||||
best_roof = response_all_roofs_decoded[0] # TODO: Find best roof
|
if(len(response_all_roofs_decoded) > 0):
|
||||||
for roof in response_all_roofs_decoded:
|
best_roof = response_all_roofs_decoded[0] # TODO: Find best roof
|
||||||
if(float(roof['attributes']['flaeche']) > float(best_roof['attributes']['flaeche'])):
|
for roof in response_all_roofs_decoded:
|
||||||
best_roof = roof
|
if(float(roof['attributes']['flaeche']) > float(best_roof['attributes']['flaeche'])):
|
||||||
url = "https://www.uvek-gis.admin.ch/BFE/sonnendach/index.html?featureId=" + str(best_roof['featureId']) + "&lang=de"
|
best_roof = roof
|
||||||
suitability = str(best_roof['attributes']['klasse'])
|
url = "https://www.uvek-gis.admin.ch/BFE/sonnendach/index.html?featureId=" + str(best_roof['featureId']) + "&lang=de"
|
||||||
pv_Production100 = str(float(best_roof['attributes']['gstrahlung'])*0.2*0.8)
|
suitability = str(best_roof['attributes']['klasse'])
|
||||||
pv_Production75 = str(float(pv_Production100) * 0.75)
|
pv_Production100 = str(float(best_roof['attributes']['gstrahlung'])*0.2*0.8)
|
||||||
pv_Production50 = str(float(pv_Production100) * 0.5)
|
value_electricity_production = str(best_roof['attributes']['finanzertrag'])
|
||||||
value_electricity_production = str(best_roof['attributes']['finanzertrag'])
|
roof_area = str(best_roof['attributes']['flaeche'])
|
||||||
roof_area = str(best_roof['attributes']['flaeche'])
|
else:
|
||||||
|
found = False
|
||||||
except:
|
except:
|
||||||
found = False
|
found = False
|
||||||
|
|
||||||
roof_is_suitable = True # TODO decide if roof is suitable
|
roof_is_suitable = True # TODO decide if roof is suitable
|
||||||
|
|
||||||
if(found and createImages.get() > 0 and roof_is_suitable):
|
if(found and createImages.get() > 0 and roof_is_suitable):
|
||||||
image_filename = suitability + " - " + address_string
|
image_filename = suitability + " - " + address_string + ".png"
|
||||||
image_folder_map = "screenshots/"
|
create_images(address_string, driver, image_filename, image_folder_map, image_folder_production, image_folder_qrcode,
|
||||||
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_images(address_string, driver, image_filename_map, image_filename_production,
|
|
||||||
image_filename_qrcode, image_folder_map, image_folder_production, image_folder_qrcode,
|
|
||||||
url)
|
url)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
image_filename_map = "not-created"
|
image_filename = "not-created"
|
||||||
image_filename_production = "not-created"
|
|
||||||
image_filename_qrcode = "not-created"
|
|
||||||
|
|
||||||
save_information_to_addresslist(adress, adress_list, columnIndexes, coordinates, file_split_char, i,
|
save_information_to_addresslist(adress, adress_list, columnIndexes, coordinates, file_split_char, i,
|
||||||
image_filename_map, image_filename_production, image_filename_qrcode,
|
image_filename, pv_Production100, roof_area, suitability, url,
|
||||||
pv_Production100, pv_Production50, pv_Production75, roof_area, suitability,
|
value_electricity_production)
|
||||||
url, value_electricity_production)
|
|
||||||
|
|
||||||
save_addresslist_in_file(adress_list, filename_adresslist)
|
save_addresslist_in_file(adress_list, filename_adresslist)
|
||||||
|
|
||||||
|
@ -187,22 +181,17 @@ def search_adresses(adress_list, filename_adresslist, driver, mainText):
|
||||||
|
|
||||||
|
|
||||||
def save_information_to_addresslist(adress, adress_list, columnIndexes, coordinates, file_split_char, list_index,
|
def save_information_to_addresslist(adress, adress_list, columnIndexes, coordinates, file_split_char, list_index,
|
||||||
image_filename_map, image_filename_production, image_filename_qrcode,
|
image_filename, pv_Production100, roof_area, suitability, url,
|
||||||
pv_Production100, pv_Production50, pv_Production75, roof_area, suitability, url,
|
|
||||||
value_electricity_production):
|
value_electricity_production):
|
||||||
# Save Information in Addresslist
|
# Save Information in Addresslist
|
||||||
adress[columnIndexes[4]] = str(coordinates[0])
|
adress[columnIndexes[4]] = str(coordinates[0])
|
||||||
adress[columnIndexes[5]] = str(coordinates[1])
|
adress[columnIndexes[5]] = str(coordinates[1])
|
||||||
adress[columnIndexes[6]] = url
|
adress[columnIndexes[6]] = url
|
||||||
adress[columnIndexes[7]] = suitability
|
adress[columnIndexes[7]] = suitability
|
||||||
adress[columnIndexes[8]] = image_filename_map
|
adress[columnIndexes[8]] = image_filename
|
||||||
adress[columnIndexes[9]] = image_filename_production
|
adress[columnIndexes[9]] = pv_Production100
|
||||||
adress[columnIndexes[10]] = image_filename_qrcode
|
adress[columnIndexes[10]] = value_electricity_production
|
||||||
adress[columnIndexes[11]] = pv_Production50
|
adress[columnIndexes[11]] = roof_area
|
||||||
adress[columnIndexes[12]] = pv_Production75
|
|
||||||
adress[columnIndexes[13]] = pv_Production100
|
|
||||||
adress[columnIndexes[14]] = value_electricity_production
|
|
||||||
adress[columnIndexes[15]] = roof_area
|
|
||||||
new_line_string = ""
|
new_line_string = ""
|
||||||
for j in adress:
|
for j in adress:
|
||||||
new_line_string = new_line_string + j + file_split_char
|
new_line_string = new_line_string + j + file_split_char
|
||||||
|
@ -219,8 +208,7 @@ def save_addresslist_in_file(adress_list, filename_adresslist):
|
||||||
adress_file.close()
|
adress_file.close()
|
||||||
|
|
||||||
|
|
||||||
def create_images(address_string, driver, image_filename_map, image_filename_production, image_filename_qrcode,
|
def create_images(address_string, driver, image_filename, image_folder_map, image_folder_production, image_folder_qrcode, url):
|
||||||
image_folder_map, image_folder_production, image_folder_qrcode, url):
|
|
||||||
driver.get(url)
|
driver.get(url)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
|
@ -228,7 +216,7 @@ def create_images(address_string, driver, image_filename_map, image_filename_pro
|
||||||
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)
|
||||||
|
|
||||||
# Create Screenshot of Map
|
# Create Screenshot of Map
|
||||||
actions = ActionChains(driver)
|
actions = ActionChains(driver)
|
||||||
|
@ -249,10 +237,10 @@ def create_images(address_string, driver, image_filename_map, image_filename_pro
|
||||||
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_map + image_filename_map)
|
driver.save_screenshot(image_folder_map + image_filename)
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
Image.open(image_folder_map + image_filename_map).crop(area).save(
|
Image.open(image_folder_map + image_filename).crop(area).save(
|
||||||
image_folder_map + image_filename_map)
|
image_folder_map + image_filename)
|
||||||
|
|
||||||
# Create Screenshot of Chart
|
# Create Screenshot of Chart
|
||||||
try:
|
try:
|
||||||
|
@ -267,10 +255,10 @@ def create_images(address_string, driver, image_filename_map, image_filename_pro
|
||||||
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_production + image_filename)
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
Image.open(image_folder_production + image_filename_production).crop(area).save(
|
Image.open(image_folder_production + image_filename).crop(area).save(
|
||||||
image_folder_production + image_filename_production)
|
image_folder_production + image_filename)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue