fixed problems with screenshots

#2
This commit is contained in:
schrom01 2022-07-27 17:30:05 +02:00
parent 58bb85660a
commit e6aa173fd0
2 changed files with 31 additions and 28 deletions

32
Main.py
View File

@ -43,7 +43,7 @@ def search_adresses(adress_list, filename_adresslist, driver):
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[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)):
print(adress) print(adress)
search_string = adress[columnIndexes[0]] + " " + adress[columnIndexes[1]] + " " + adress[columnIndexes[2]] + " " + adress[columnIndexes[3]] search_string = adress[columnIndexes[0]] + " " + adress[columnIndexes[1]] + " " + adress[columnIndexes[2]] + " " + adress[columnIndexes[3]]
search_bar = driver.find_element(By.ID, "searchTypeahead1") search_bar = driver.find_element(By.ID, "searchTypeahead1")
@ -85,7 +85,8 @@ def search_adresses(adress_list, filename_adresslist, driver):
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 # Create Screenshot of Map
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);""")
@ -97,29 +98,29 @@ def search_adresses(adress_list, filename_adresslist, driver):
location = mapElement.location location = mapElement.location
size = mapElement.size size = mapElement.size
x = location["x"] x = location["x"]
y = 43 # location["y"] y = location["y"]
w = x + size["width"] w = x + size["width"]
h = y + size["height"] h = size["height"]
area = (x, y, w, h) area = (x, 0, w, h)
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_map)
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_map).crop(area).save(
image_folder_map + image_filename_map) image_folder_map + image_filename_map)
# take Screenshot 2 # Create Screenshot of Chart
try: try:
chartElement = driver.find_element(By.ID, "chart") chartElement = driver.find_elements(By.XPATH, "//div[@id='chart']//*")[0]
actions = ActionChains(driver)
actions.move_to_element(chartElement).perform()
location = chartElement.location location = chartElement.location
size = chartElement.size size = chartElement.size
x = 920 x = location["x"]
y = 1000 y = location["y"]
w = 1600 w = x + size["width"]
h = 1300 h = size["height"]
area = (x, y, w, h) area = (x, 0, w, h)
print("X: " + str(x) + "Y: " + str(y) + "W: " + str(w) + "H: " + str(h)) driver.execute_script("window.scrollTo(0, " + str(y) + ")")
print("X: " + str(x) + " Y: " + str(y) + " W: " + str(w) + " H: " + str(h))
time.sleep(1) time.sleep(1)
driver.save_screenshot(image_folder_production + image_filename_production) driver.save_screenshot(image_folder_production + image_filename_production)
@ -171,6 +172,7 @@ def search_adresses(adress_list, filename_adresslist, driver):
print("closing Thread") print("closing Thread")
break break
print("closing Thread")
def read_adresslist(filename_adresslist): def read_adresslist(filename_adresslist):
returnvalues = [] returnvalues = []

View File

@ -19,7 +19,7 @@ driver = webdriver.Chrome(service=s)
driver.minimize_window() driver.minimize_window()
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(5)
try: try:
if(not os.path.exists("screenshots")): if(not os.path.exists("screenshots")):
@ -81,6 +81,7 @@ try:
"qrcodes/" + image_filename + "production" + ".png") "qrcodes/" + image_filename + "production" + ".png")
# Create Screenshot # Create Screenshot
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);""")
@ -92,27 +93,27 @@ try:
location = mapElement.location location = mapElement.location
size = mapElement.size size = mapElement.size
x = location["x"] x = location["x"]
y = 43 # location["y"] y = location["y"]
w = x + size["width"] w = x + size["width"]
h = y + size["height"] h = size["height"]
area = (x, y, w, h) area = (x, 0, w, h)
driver.execute_script("window.scrollTo(0, " + str(y) + ")")
time.sleep(1) time.sleep(1)
driver.save_screenshot("screenshots/" + image_filename + "map" + ".png") driver.save_screenshot("screenshots/" + image_filename + "map" + ".png")
time.sleep(0.2) time.sleep(0.2)
Image.open("screenshots/" + image_filename + "map" + ".png").crop(area).save("screenshots/" + image_filename + "map" + ".png") Image.open("screenshots/" + image_filename + "map" + ".png").crop(area).save("screenshots/" + image_filename + "map" + ".png")
#take Screenshot 2 #take Screenshot 2
chartElement = driver.find_element(By.ID, "chart") chartElement = driver.find_elements(By.XPATH, "//div[@id='chart']//*")[0]
actions = ActionChains(driver)
actions.move_to_element(chartElement).perform()
location = chartElement.location location = chartElement.location
size = chartElement.size size = chartElement.size
x = 920 x = location["x"]
y = 1000 y = location["y"]
w = 1600 w = x + size["width"]
h = 1300 h = size["height"]
area = (x, y, w, h) area = (x, 0, w, h)
print("X: " + str(x) + "Y: "+ str(y) + "W: "+ str(w) + "H: " + str(h)) driver.execute_script("window.scrollTo(0, " + str(y) + ")")
print("X: " + str(x) + " Y: "+ str(y) + " W: "+ str(w) + " H: " + str(h))
time.sleep(1) time.sleep(1)
driver.save_screenshot("screenshots/" + image_filename + "production" + ".png") driver.save_screenshot("screenshots/" + image_filename + "production" + ".png")