diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 7143502..c4f72ec 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -8,10 +8,3 @@ RUN python3 -m pip install --upgrade pip RUN python3 -m pip install --user virtualenv ENV TZ=Europe/Berlin 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"] \ No newline at end of file diff --git a/inkycal/modules/inkycal_openweather_scrape.py b/inkycal/modules/inkycal_openweather_scrape.py index 45b1ab9..e6a4f74 100644 --- a/inkycal/modules/inkycal_openweather_scrape.py +++ b/inkycal/modules/inkycal_openweather_scrape.py @@ -1,11 +1,9 @@ -import sys import time from PIL import Image from PIL import ImageEnhance from selenium import webdriver from selenium.common.exceptions import ElementClickInterceptedException -from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import TimeoutException from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service @@ -16,7 +14,7 @@ from selenium.webdriver.support.wait import WebDriverWait def get_scraped_weatherforecast_image() -> Image: # Set the desired viewport size (width, height) my_width = 480 - my_height = 850 + my_height = 850 # will later be cropped mobile_emulation = { "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", @@ -26,14 +24,13 @@ def get_scraped_weatherforecast_image() -> Image: options = Options() options.add_argument("--no-sandbox") options.add_argument("--headless=new") - # options.add_argument("--disable-gpu") options.add_argument("--disable-dev-shm-usage") options.add_experimental_option("mobileEmulation", mobile_emulation) service = Service("/usr/bin/chromedriver") driver = webdriver.Chrome(service=service, options=options) # Navigate to webpage - driver.get("https://openweathermap.org/city/2867714") + driver.get("https://openweathermap.org/city/") # Wait and find the Cookie 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]') 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]') # 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%'") html_element = driver.find_element(By.TAG_NAME, "html") @@ -88,11 +85,10 @@ def get_scraped_weatherforecast_image() -> Image: # Close the WebDriver when done 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 = im.crop((0, 100, (my_width - 50), (my_height - 50))) im = im.resize((480, 800), resample=Image.LANCZOS) - # im = im.rotate(90, Image.NEAREST, expand = 1) im = ImageEnhance.Contrast(im).enhance(1.0) im.save(image_filename) return im, im diff --git a/run_weather_scraper.sh b/run_weather_scraper.sh deleted file mode 100755 index 7da98fd..0000000 --- a/run_weather_scraper.sh +++ /dev/null @@ -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/