-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrss-to-urls
More file actions
executable file
·58 lines (47 loc) · 1.45 KB
/
rss-to-urls
File metadata and controls
executable file
·58 lines (47 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.12"
# dependencies = ["feedparser"]
# ///
import feedparser
import sys
def rss_to_links(rss_url):
"""
Parse an RSS feed and return a list of links to the entries.
Args:
rss_url: URL of the RSS feed to parse
Returns:
A list of links from the feed
"""
try:
# Parse the feed
feed = feedparser.parse(rss_url)
# Check if there was an error parsing the feed
if feed.bozo and hasattr(feed, 'bozo_exception'):
print(f"Error parsing feed: {feed.bozo_exception}", file=sys.stderr)
return []
# Extract links from entries
links = []
for entry in feed.entries:
if hasattr(entry, 'link'):
links.append(entry.link)
return links
except Exception as e:
print(f"Error: {str(e)}", file=sys.stderr)
return []
def main():
# Check if URL was provided as command line argument
if len(sys.argv) < 2:
print("Usage: python rss_to_links.py <rss_url>", file=sys.stderr)
sys.exit(1)
rss_url = sys.argv[1]
links = rss_to_links(rss_url)
if links:
# Print each link on a new line
for link in links:
print(link)
else:
print("No links found in the feed.", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()