some cleanup
This commit is contained in:
		| @@ -8,10 +8,3 @@ RUN python3 -m pip install --upgrade pip | |||||||
| RUN python3 -m pip install --user virtualenv | RUN python3 -m pip install --user virtualenv | ||||||
| ENV TZ=Europe/Berlin | ENV TZ=Europe/Berlin | ||||||
| RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone | RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone | ||||||
|  |  | ||||||
| FROM development |  | ||||||
| COPY ../inkycal/modules/inkycal_openweather_scrape.py /app/ |  | ||||||
| COPY ./run_weather_scraper.sh /app/ |  | ||||||
|  |  | ||||||
| # Set the entrypoint to the shell script |  | ||||||
| ENTRYPOINT ["run_weather_scraper.sh"] |  | ||||||
| @@ -1,11 +1,9 @@ | |||||||
| import sys |  | ||||||
| import time | import time | ||||||
|  |  | ||||||
| from PIL import Image | from PIL import Image | ||||||
| from PIL import ImageEnhance | from PIL import ImageEnhance | ||||||
| from selenium import webdriver | from selenium import webdriver | ||||||
| from selenium.common.exceptions import ElementClickInterceptedException | from selenium.common.exceptions import ElementClickInterceptedException | ||||||
| from selenium.common.exceptions import NoSuchElementException |  | ||||||
| from selenium.common.exceptions import TimeoutException | from selenium.common.exceptions import TimeoutException | ||||||
| from selenium.webdriver.chrome.options import Options | from selenium.webdriver.chrome.options import Options | ||||||
| from selenium.webdriver.chrome.service import Service | from selenium.webdriver.chrome.service import Service | ||||||
| @@ -16,7 +14,7 @@ from selenium.webdriver.support.wait import WebDriverWait | |||||||
| def get_scraped_weatherforecast_image() -> Image: | def get_scraped_weatherforecast_image() -> Image: | ||||||
|     # Set the desired viewport size (width, height) |     # Set the desired viewport size (width, height) | ||||||
|     my_width = 480 |     my_width = 480 | ||||||
|     my_height = 850 |     my_height = 850 # will later be cropped | ||||||
|     mobile_emulation = { |     mobile_emulation = { | ||||||
|         "deviceMetrics": {"width": my_width, "height": my_height, "pixelRatio": 1.0}, |         "deviceMetrics": {"width": my_width, "height": my_height, "pixelRatio": 1.0}, | ||||||
|         "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19", |         "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19", | ||||||
| @@ -26,14 +24,13 @@ def get_scraped_weatherforecast_image() -> Image: | |||||||
|     options = Options() |     options = Options() | ||||||
|     options.add_argument("--no-sandbox") |     options.add_argument("--no-sandbox") | ||||||
|     options.add_argument("--headless=new") |     options.add_argument("--headless=new") | ||||||
|     # options.add_argument("--disable-gpu") |  | ||||||
|     options.add_argument("--disable-dev-shm-usage") |     options.add_argument("--disable-dev-shm-usage") | ||||||
|     options.add_experimental_option("mobileEmulation", mobile_emulation) |     options.add_experimental_option("mobileEmulation", mobile_emulation) | ||||||
|     service = Service("/usr/bin/chromedriver") |     service = Service("/usr/bin/chromedriver") | ||||||
|     driver = webdriver.Chrome(service=service, options=options) |     driver = webdriver.Chrome(service=service, options=options) | ||||||
|  |  | ||||||
|     # Navigate to webpage |     # Navigate to webpage | ||||||
|     driver.get("https://openweathermap.org/city/2867714") |     driver.get("https://openweathermap.org/city/<your_city_id_here>") | ||||||
|  |  | ||||||
|     # Wait and find the Cookie Button |     # Wait and find the Cookie Button | ||||||
|     login_button = driver.find_element(By.XPATH, '//*[@id="stick-footer-panel"]/div/div/div/div/div/button') |     login_button = driver.find_element(By.XPATH, '//*[@id="stick-footer-panel"]/div/div/div/div/div/button') | ||||||
| @@ -71,11 +68,11 @@ def get_scraped_weatherforecast_image() -> Image: | |||||||
|     map_element = driver.find_element(By.XPATH, '//*[@id="weather-widget"]/div[2]/div[1]/div[2]') |     map_element = driver.find_element(By.XPATH, '//*[@id="weather-widget"]/div[2]/div[1]/div[2]') | ||||||
|     driver.execute_script("arguments[0].remove();", map_element) |     driver.execute_script("arguments[0].remove();", map_element) | ||||||
|  |  | ||||||
|     # remove the hourly forecast |     # optional: remove the hourly forecast | ||||||
|     # map_element = driver.find_element(By.XPATH, '//*[@id="weather-widget"]/div[2]/div[2]/div[1]') |     # map_element = driver.find_element(By.XPATH, '//*[@id="weather-widget"]/div[2]/div[2]/div[1]') | ||||||
|     # driver.execute_script("arguments[0].remove();", map_element) |     # driver.execute_script("arguments[0].remove();", map_element) | ||||||
|  |  | ||||||
|     # zoom in a little - not now |     # zoom in a little | ||||||
|     driver.execute_script("document.body.style.zoom='110%'") |     driver.execute_script("document.body.style.zoom='110%'") | ||||||
|  |  | ||||||
|     html_element = driver.find_element(By.TAG_NAME, "html") |     html_element = driver.find_element(By.TAG_NAME, "html") | ||||||
| @@ -88,11 +85,10 @@ def get_scraped_weatherforecast_image() -> Image: | |||||||
|     # Close the WebDriver when done |     # Close the WebDriver when done | ||||||
|     driver.quit() |     driver.quit() | ||||||
|  |  | ||||||
|     # crop, resize, enhance & rotate the image for inky display |     # crop, resize, enhance & rotate the image for inky 7in5 v2 colour display | ||||||
|     im = Image.open(image_filename, mode="r", formats=None) |     im = Image.open(image_filename, mode="r", formats=None) | ||||||
|     im = im.crop((0, 100, (my_width - 50), (my_height - 50))) |     im = im.crop((0, 100, (my_width - 50), (my_height - 50))) | ||||||
|     im = im.resize((480, 800), resample=Image.LANCZOS) |     im = im.resize((480, 800), resample=Image.LANCZOS) | ||||||
|     # im = im.rotate(90, Image.NEAREST, expand = 1) |  | ||||||
|     im = ImageEnhance.Contrast(im).enhance(1.0) |     im = ImageEnhance.Contrast(im).enhance(1.0) | ||||||
|     im.save(image_filename) |     im.save(image_filename) | ||||||
|     return im, im |     return im, im | ||||||
|   | |||||||
| @@ -1,3 +0,0 @@ | |||||||
| #!/bin/sh |  | ||||||
| python3 /home/ubuntu/Inkycal/inkycal/modules/inkycal_openweather_scrape.py |  | ||||||
| scp -i /home/ubuntu/.ssh/id_rsa /tmp/openweather_scraped.png inky@10.10.9.10:~/Inkycal/ |  | ||||||
		Reference in New Issue
	
	Block a user
	 mrbwburns
					mrbwburns