From 4b1ea2da11257e599ee1540aa9108ce48a222725 Mon Sep 17 00:00:00 2001 From: Joe Gitta Date: Wed, 27 May 2026 14:09:15 +0000 Subject: [PATCH] feat: add local ad-free newspaper --- VERSION | 2 +- browser.py | 65 +++++++++++ config.json | 2 +- deploy.sh | 9 ++ install-kiosk.sh | 1 + news.html | 282 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 359 insertions(+), 2 deletions(-) create mode 100644 news.html diff --git a/VERSION b/VERSION index 53a75d6..3a4036f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.6 +0.2.5 diff --git a/browser.py b/browser.py index 3e45627..9398472 100755 --- a/browser.py +++ b/browser.py @@ -863,11 +863,76 @@ if __name__ == "__main__": # Update cache every 15 minutes time.sleep(900) + def update_news_cache(): + """Fetch top RSS news feeds (BBC, NPR) in background and cache as local JSON to bypass CORS/Ads.""" + import xml.etree.ElementTree as ET + import re + cache_file = _HOME / "kiosk-home" / "news-data.json" + + feeds = { + "World News": "http://feeds.bbci.co.uk/news/world/rss.xml", + "National News": "https://feeds.npr.org/1001/rss.xml" + } + + while True: + payload = {} + for category, url in feeds.items(): + try: + req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"}) + xml_raw = urllib.request.urlopen(req, timeout=12).read() + root = ET.fromstring(xml_raw) + + stories = [] + channel = root.find("channel") + if channel is not None: + # Fetch up to 10 stories per category + for idx, item in enumerate(channel.findall("item")): + if idx >= 10: + break + title = item.find("title") + desc = item.find("description") + pub_date = item.find("pubDate") + + t_str = title.text.strip() if title is not None and title.text else "" + d_str = desc.text.strip() if desc is not None and desc.text else "" + + # Clean HTML tags from description if any + d_str = re.sub('<[^<]+?>', '', d_str) + + p_str = "" + if pub_date is not None and pub_date.text: + try: + p_str = " ".join(pub_date.text.split()[:4]) + except Exception: + p_str = pub_date.text + + stories.append({ + "title": t_str, + "summary": d_str, + "date": p_str + }) + payload[category] = stories + print(f"Successfully cached {len(stories)} stories for category: {category}") + except Exception as e: + print(f"Failed to fetch RSS category {category}: {e}") + + if payload: + try: + cache_file.parent.mkdir(parents=True, exist_ok=True) + cache_file.write_text(json.dumps(payload, indent=2)) + print("Updated local news-data.json cache successfully") + except Exception as e: + print(f"Failed to write news cache file: {e}") + + # Update news every 30 minutes + time.sleep(1800) + def init_cdp(): if cdp.wait_ready(timeout=30): print("CDP ready — persistent WebSocket connected successfully") threading.Thread(target=update_weather_cache, daemon=True).start() + threading.Thread(target=update_news_cache, daemon=True).start() threading.Thread(target=init_cdp, daemon=True).start() sys.exit(app.exec_()) diff --git a/config.json b/config.json index 168c4a2..0ae9634 100644 --- a/config.json +++ b/config.json @@ -3,7 +3,7 @@ "email": "https://mail.jgitta.com/roundcube/", "internet": "https://www.duckduckgo.com", "weather": "weather.html", - "news": "https://news.google.com", + "news": "news.html", "facebook": "https://www.facebook.com", "messenger": "https://www.messenger.com", "youtube": "https://www.youtube.com" diff --git a/deploy.sh b/deploy.sh index b684cd6..f2b0ea3 100755 --- a/deploy.sh +++ b/deploy.sh @@ -11,6 +11,8 @@ HOME_SRC="$REPO_DIR/home-screen-index.html" HOME_DST="/home/jgitta/kiosk-home/index.html" WEATHER_SRC="$REPO_DIR/weather.html" WEATHER_DST="/home/jgitta/kiosk-home/weather.html" +NEWS_SRC="$REPO_DIR/news.html" +NEWS_DST="/home/jgitta/kiosk-home/news.html" CONFIG_SRC="$REPO_DIR/config.json" # Auto-increment patch version (0.2.0 → 0.2.1 → 0.2.2 ...) VERSION_FILE="$REPO_DIR/VERSION" @@ -62,6 +64,12 @@ if [ -f "$WEATHER_SRC" ]; then echo " Synced weather page" fi +if [ -f "$NEWS_SRC" ]; then + cp "$NEWS_SRC" "$NEWS_DST" + chown jgitta:jgitta "$NEWS_DST" 2>/dev/null || true + echo " Synced news page" +fi + echo "==> Committing and pushing to Gitea..." git -C "$REPO_DIR" add -A git -C "$REPO_DIR" commit -m "$COMMIT_MSG" 2>/dev/null || echo " (nothing new to commit)" @@ -95,6 +103,7 @@ if [ -n "$KIOSK" ]; then config_json=\\\$(cat config.json | sed 's/\\\\\\\\/\\\\\\\\\\\\\\\\/g' | sed 's/\\\"/\\\\\\\"/g' | tr '\\\n' ' ') sed \"s|const config = {};|const config = \\\$config_json;|\" home-screen-index.html > /home/jgitta/kiosk-home/index.html cp weather.html /home/jgitta/kiosk-home/weather.html + cp news.html /home/jgitta/kiosk-home/news.html /usr/local/bin/kiosk-restart " echo " Production updated." diff --git a/install-kiosk.sh b/install-kiosk.sh index 2345d3c..7f5ba3b 100755 --- a/install-kiosk.sh +++ b/install-kiosk.sh @@ -47,6 +47,7 @@ apt-get install -y \ git \ curl \ openssh-server \ + fonts-noto-color-emoji \ 2>&1 | grep -Ev "^(Reading|Selecting|Preparing|Unpacking|Setting|Processing|Triggers|Get)" # ── Kiosk repo ───────────────────────────────────────────────────── diff --git a/news.html b/news.html new file mode 100644 index 0000000..c119b83 --- /dev/null +++ b/news.html @@ -0,0 +1,282 @@ + + + + + + News + + + + +
+
+

📰 Daily Newspaper

+

Today's Edition

+
+ +
🗞️ Delivery in progress... Please wait.
+ + + + +
+ + + +