From 6723f3d4d21a8d6968741d8ff06ff779540ad987 Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Fri, 17 Feb 2023 20:21:44 +0100 Subject: [PATCH] Screenshotter url test --- screenshotter/config.yaml | 2 +- screenshotter/rootfs/app/app.py | 24 ++++++++++++++--------- screenshotter/rootfs/app/requirements.txt | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/screenshotter/config.yaml b/screenshotter/config.yaml index dec95e6..5634dfa 100644 --- a/screenshotter/config.yaml +++ b/screenshotter/config.yaml @@ -1,6 +1,6 @@ --- name: E-Paper Screenshotter -version: 1.0.1.19 +version: 1.0.1.20 #image: ghcr.io/maxwinterstein/homeassistant-addon-toogoodtogo-ha-mqtt-bridge-{arch} slug: screenshotter description: Screenshot images for E-Paper pricetags diff --git a/screenshotter/rootfs/app/app.py b/screenshotter/rootfs/app/app.py index f9b6645..6d70f2a 100644 --- a/screenshotter/rootfs/app/app.py +++ b/screenshotter/rootfs/app/app.py @@ -1,8 +1,8 @@ -from selenium import webdriver -from selenium.webdriver.chrome.options import Options +from seleniumwire import webdriver +from seleniumwire.webdriver.chrome.options import Options +from seleniumwire.webdriver.common.desired_capabilities import DesiredCapabilities from PIL import Image import time, os -from selenium.webdriver.common.desired_capabilities import DesiredCapabilities import yaml import datetime import croniter @@ -60,15 +60,21 @@ while True: logging.info(f"Running {task['name']}") driver = webdriver.Chrome(options=chrome_options, desired_capabilities=d) driver.implicitly_wait(10) - driver.get(task["url"]) - time.sleep(int(wait)) if task.get("ha_auth"): - logging.info("Doing HA Auth") - driver.execute_script(f"window.localStorage.setItem('hassTokens', JSON.stringify({{hassUrl: '{ha_url}', access_token: '{ha_token}', token_type: 'Bearer'}}));") - driver.get(task["url"]) - time.sleep(int(wait)) + def interceptor(request): + if request.headers['Authorization']: + del request.headers['Authorization'] # Remember to delete the header first + request.headers['Authorization'] = f"Bearer {ha_token}" # Spoof the referer + driver.request_interceptor = interceptor + #logging.info("Doing HA Auth") + #driver.execute_script(f"window.localStorage.setItem('hassTokens', JSON.stringify({{hassUrl: '{ha_url}', access_token: '{ha_token}', token_type: 'Bearer'}}));") + #driver.get(task["url"]) + #time.sleep(int(wait)) + driver.get(task["url"]) + time.sleep(int(wait)) + logging.info("Making screenshot") # save screenshot diff --git a/screenshotter/rootfs/app/requirements.txt b/screenshotter/rootfs/app/requirements.txt index 9e8fae1..70f4c85 100644 --- a/screenshotter/rootfs/app/requirements.txt +++ b/screenshotter/rootfs/app/requirements.txt @@ -1,4 +1,4 @@ -selenium +selenium-wire Pillow pyyaml croniter