bump devcontainer to bookworm, add documentation

This commit is contained in:
mrbwburns
2023-11-26 20:29:02 +01:00
parent a7c3edc60e
commit b885105147
5 changed files with 37 additions and 308 deletions

View File

@@ -1,29 +1,32 @@
import sys
import time
from PIL import Image
from PIL import ImageEnhance
from selenium import webdriver
from selenium.common.exceptions import ElementClickInterceptedException, TimeoutException, NoSuchElementException
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
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
import sys
import time
def get_scraped_weatherforecast_image() -> Image:
# Set the desired viewport size (width, height)
my_width = 480
my_height = 850
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"
"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",
}
# Create an instance of the webdriver with some pre-configured options
options = Options()
options.add_argument("--no-sandbox")
options.add_argument("--headless=new")
#options.add_argument("--disable-gpu")
# options.add_argument("--disable-gpu")
options.add_argument("--disable-dev-shm-usage")
options.add_experimental_option("mobileEmulation", mobile_emulation)
service = Service("/usr/bin/chromedriver")
@@ -38,7 +41,7 @@ def get_scraped_weatherforecast_image() -> Image:
driver.execute_script("return arguments[0].scrollIntoView();", login_button)
# Click the button
button_clicked = False
while(button_clicked == False):
while button_clicked == False:
try:
login_button.click()
button_clicked = True
@@ -49,9 +52,12 @@ def get_scraped_weatherforecast_image() -> Image:
# hacky wait statement for all the page elements to load
page_loaded = False
while(page_loaded == False):
while page_loaded == False:
try:
WebDriverWait(driver, timeout=45).until(lambda d: d.find_element(By.XPATH, '//*[@id="weather-widget"]/div[2]/div[1]/div[1]/div[1]/h2').text != "")
WebDriverWait(driver, timeout=45).until(
lambda d: d.find_element(By.XPATH, '//*[@id="weather-widget"]/div[2]/div[1]/div[1]/div[1]/h2').text
!= ""
)
page_loaded = True
except TimeoutException:
print("Couldn't get the page to load, retrying...")
@@ -66,11 +72,11 @@ def get_scraped_weatherforecast_image() -> Image:
driver.execute_script("arguments[0].remove();", map_element)
# 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)
# 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
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")
driver.execute_script("arguments[0].style.fontSize = '16px';", html_element)
@@ -83,18 +89,20 @@ def get_scraped_weatherforecast_image() -> Image:
driver.quit()
# crop, resize, enhance & rotate the image for inky display
im = Image.open(image_filename, mode='r', formats=None)
im = im.crop((0, 100, (my_width-50), (my_height-50)))
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 = im.rotate(90, Image.NEAREST, expand = 1)
im = ImageEnhance.Contrast(im).enhance(1.0)
im.save(image_filename)
return im, im
def main():
_, _ = get_scraped_weatherforecast_image()
if __name__ == '__main__':
if __name__ == "__main__":
now = time.asctime()
print(f"It's {now} - running {__name__} in standalone/debug mode")
main()