RSS-Downloader/index.py

29 lines
902 B
Python
Raw Normal View History

2025-04-01 19:55:33 +00:00
import feedparser
import os
import requests
def download_attachment(url, filename):
response = requests.get(url)
if response.status_code == 200:
with open(filename, 'wb') as f:
f.write(response.content)
print(f"Downloaded {filename}")
else:
print(f"Failed to download {url}")
def main():
feed_url = input("Enter the RSS feed URL: ")
num_entries = int(input("Enter the number of entries to process: "))
feed = feedparser.parse(feed_url)
for i, entry in enumerate(feed.entries[:num_entries]):
if hasattr(entry, 'links'):
for link in entry.links:
if link.type == 'application/pdf' or link.type.endswith('/zip') or link.type.endswith('/rar'):
filename = os.path.basename(link.href)
download_attachment(link.href, filename)
if __name__ == "__main__":
main()