implemented qr-Code

This commit is contained in:
romanschenk37 2022-03-11 22:18:02 +01:00
parent e0f4d585df
commit 1ce1657a65
1 changed files with 27 additions and 9 deletions

36
Main.py
View File

@ -7,12 +7,12 @@ from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.keys import Keys
from PIL import Image from PIL import Image
import os import os
import qrcode
from tkinter import filedialog from tkinter import filedialog
import time import time
DropDownLabels = ["Street: ", "Number: ", "Postal code: ", "City: ", "Sonnendach URL: ", "Eignung", "Screenshot Filename: "] DropDownLabels = ["Street: ", "Number: ", "Postal code: ", "City: ", "Sonnendach URL: ", "Eignung", "Screenshot Filename: ", "PV Production 50", "PV Production 75", "PV Production 100", "Value Electricity production"]
file_split_char = "," file_split_char = ","
OptionList = [] OptionList = []
exit = False exit = False
@ -35,6 +35,8 @@ def search_adresses(adress_list, filename_adresslist, driver):
if(not os.path.exists("screenshots")): if(not os.path.exists("screenshots")):
os.makedirs("screenshots", exist_ok=False) os.makedirs("screenshots", exist_ok=False)
if (not os.path.exists("qrcodes")):
os.makedirs("qrcodes", exist_ok=False)
for i in range(len(adress_list)): for i in range(len(adress_list)):
line = adress_list[i] line = adress_list[i]
@ -62,11 +64,22 @@ def search_adresses(adress_list, filename_adresslist, driver):
time.sleep(2) time.sleep(2)
url = driver.current_url url = driver.current_url
eignung = driver.find_element(By.ID, "eignung") eignung = driver.find_element(By.ID, "eignung")
image_filename = "screenshots/" + eignung.text + " - " + search_string + ".png" image_filename = eignung.text + " - " + search_string + ".png"
pv_Production50 = "50"
pv_Production75 = "75"
pv_Production100 = "100"
value_electricity_production = "value"
adress[columnIndexes[4]] = url adress[columnIndexes[4]] = url
adress[columnIndexes[5]] = eignung.text adress[columnIndexes[5]] = eignung.text
adress[columnIndexes[6]] = image_filename adress[columnIndexes[6]] = image_filename
adress[columnIndexes[7]] = pv_Production50
adress[columnIndexes[8]] = pv_Production75
adress[columnIndexes[9]] = pv_Production100
adress[columnIndexes[10]] = value_electricity_production
adress_file = open(filename_adresslist, "w") adress_file = open(filename_adresslist, "w")
new_line_string = "" new_line_string = ""
@ -79,20 +92,25 @@ def search_adresses(adress_list, filename_adresslist, driver):
adress_file.write(new_adress_list) adress_file.write(new_adress_list)
adress_file.close() adress_file.close()
featureElement = driver.find_element(By.XPATH, #Create Screenshot
"//section[@id='one']//div[@class='container']//div[@class='row 150%']") featureElement = driver.find_element(By.XPATH, "//section[@id='one']//div[@class='container']//div[@class='row 150%']")
location = featureElement.location location = featureElement.location
size = featureElement.size size = featureElement.size
driver.save_screenshot(image_filename) driver.save_screenshot("screenshots/" + image_filename)
x = location["x"] x = location["x"]
y = 0 # location["y"] y = 0 # location["y"]
w = x + size["width"] w = x + size["width"]
h = y + size["height"] - 100 h = y + size["height"] - 100
area = (x, y, w, h) area = (x, y, w, h)
print(area) fullImg = Image.open("screenshots/" + image_filename)
fullImg = Image.open(image_filename)
cropImg = fullImg.crop(area) cropImg = fullImg.crop(area)
cropImg.save(image_filename) cropImg.save("screenshots/" + image_filename)
#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("qrcodes/" + image_filename)
print(image_filename + " was saved.") print(image_filename + " was saved.")