-
Notifications
You must be signed in to change notification settings - Fork 0
Add “Open in Reader” button to open generated RSS feeds in feed readers #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| if [[ $# -lt 1 ]]; then | ||
| echo "Usage: $0 <feed_url> [--interval SECONDS] [--limit N]" | ||
| exit 1 | ||
| fi | ||
|
|
||
| python scripts/terminal_reader.py "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #!/usr/bin/env python3 | ||
| """Simple terminal RSS reader host. | ||
|
|
||
| Fetches an RSS/Atom feed on an interval and prints new entries to the terminal. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import time | ||
| import urllib.request | ||
| import xml.etree.ElementTree as ET | ||
| from datetime import datetime | ||
|
|
||
|
|
||
| def fetch_feed(feed_url: str, timeout: int = 20) -> bytes: | ||
| req = urllib.request.Request(feed_url, headers={"User-Agent": "TerminalRSSReader/1.0"}) | ||
| with urllib.request.urlopen(req, timeout=timeout) as response: | ||
| return response.read() | ||
|
|
||
|
|
||
| def parse_entries(xml_bytes: bytes, limit: int) -> list[tuple[str, str, str]]: | ||
| root = ET.fromstring(xml_bytes) | ||
|
|
||
| entries: list[tuple[str, str, str]] = [] | ||
|
|
||
| # RSS | ||
| for item in root.findall('.//item'): | ||
| title = (item.findtext('title') or 'Untitled').strip() | ||
| link = (item.findtext('link') or '').strip() | ||
| published = (item.findtext('pubDate') or 'Unknown date').strip() | ||
| entries.append((title, link, published)) | ||
|
|
||
| # Atom fallback | ||
| if not entries: | ||
| ns = {'atom': 'http://www.w3.org/2005/Atom'} | ||
| for entry in root.findall('.//atom:entry', ns): | ||
| title = (entry.findtext('atom:title', default='Untitled', namespaces=ns) or 'Untitled').strip() | ||
| link_el = entry.find('atom:link', ns) | ||
| link = (link_el.attrib.get('href', '') if link_el is not None else '').strip() | ||
| published = (entry.findtext('atom:published', default='Unknown date', namespaces=ns) or 'Unknown date').strip() | ||
| entries.append((title, link, published)) | ||
|
|
||
| return entries[:limit] | ||
|
|
||
|
|
||
| def main() -> int: | ||
| parser = argparse.ArgumentParser(description='Host a simple RSS reader in your terminal.') | ||
| parser.add_argument('feed_url', help='RSS/Atom feed URL to watch') | ||
| parser.add_argument('--interval', type=int, default=120, help='Seconds between refreshes (default: 120)') | ||
| parser.add_argument('--limit', type=int, default=10, help='Maximum entries to show per refresh (default: 10)') | ||
| args = parser.parse_args() | ||
|
|
||
| seen_links: set[str] = set() | ||
|
|
||
| print(f"\n📡 Terminal Reader started for: {args.feed_url}") | ||
| print(f"⏱ Refresh interval: {args.interval}s | 🧾 Entry limit: {args.limit}") | ||
| print("Press Ctrl+C to stop.\n") | ||
|
|
||
| try: | ||
| while True: | ||
| timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC') | ||
| try: | ||
| xml_bytes = fetch_feed(args.feed_url) | ||
| entries = parse_entries(xml_bytes, args.limit) | ||
| print(f"\n=== Refresh @ {timestamp} ===") | ||
| if not entries: | ||
| print('No entries found.') | ||
| for idx, (title, link, published) in enumerate(entries, start=1): | ||
| marker = '🆕' if link and link not in seen_links else ' ' | ||
| print(f"{idx:02d}. {marker} {title}") | ||
| print(f" Date: {published}") | ||
| if link: | ||
| print(f" Link: {link}") | ||
| if link: | ||
| seen_links.add(link) | ||
| except Exception as exc: | ||
| print(f"Error fetching/parsing feed: {exc}") | ||
|
|
||
| time.sleep(args.interval) | ||
| except KeyboardInterrupt: | ||
| print("\nStopped terminal reader.") | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| raise SystemExit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.