Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions apps/sht20/sht20_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@
app = Flask(__name__)


def find_chrome_executable():
"""Return path to a Chrome/Chromium executable if installed."""
candidates = [
"chromium-browser",
"chromium",
"google-chrome",
"google-chrome-stable",
"chrome",
]
for name in candidates:
path = shutil.which(name)
if path:
return path
return None


def get_ip_address():
"""Return the host's primary IP address."""
ip = "127.0.0.1"
Expand Down Expand Up @@ -182,7 +198,14 @@ async def _capture_with_pyppeteer(url, outfile):
"""Use headless Chrome to capture a screenshot of the dashboard."""
from pyppeteer import launch

browser = await launch(args=["--no-sandbox"])
chrome_path = find_chrome_executable()
if not chrome_path:
raise RuntimeError(
"Chrome/Chromium not found. Please install it to capture screenshots."
)

browser = await launch(executablePath=chrome_path, args=["--no-sandbox"])

page = await browser.newPage()
await page.setViewport({"width": 1024, "height": 768})
# Wait for all network activity (including Chart.js) to finish
Expand Down Expand Up @@ -212,8 +235,6 @@ def capture_and_send(url, outfile="dashboard.jpg"):


if __name__ == "__main__":
import shutil

influx_proc = start_influxdb()
if influx_proc is not None:
import atexit
Expand Down
Loading