second attempt

This commit is contained in:
PK13274 2025-04-01 15:02:54 -05:00
parent ccbc7955af
commit 55cff8e3e3
2 changed files with 37 additions and 29 deletions

View File

@ -1,28 +1,36 @@
import feedparser import feedparser
import os import os
import requests import requests
def download_attachment(url, filename): def download_attachment(url, filename):
response = requests.get(url) response = requests.get(url)
if response.status_code == 200: if response.status_code == 200:
with open(filename, 'wb') as f: with open(filename, 'wb') as f:
f.write(response.content) f.write(response.content)
print(f"Downloaded {filename}") print(f"Downloaded {filename}")
else: else:
print(f"Failed to download {url}") print(f"Failed to download {url}")
def main(): def create_downloads_folder():
feed_url = input("Enter the RSS feed URL: ") downloads_folder = "Downloads"
num_entries = int(input("Enter the number of entries to process: ")) if not os.path.exists(downloads_folder):
os.makedirs(downloads_folder)
print(f"Created folder: {downloads_folder}")
feed = feedparser.parse(feed_url) def main():
feed_url = input("Enter the RSS feed URL: ")
num_entries = int(input("Enter the number of entries to process: "))
for i, entry in enumerate(feed.entries[:num_entries]): create_downloads_folder()
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__": feed = feedparser.parse(feed_url)
main()
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(os.path.join("Downloads", filename), link.href)
if __name__ == "__main__":
main()

View File

@ -1,13 +1,13 @@
{ {
"name": "rss-feed-downloader", "name": "rss-feed-attachment-downloader",
"version": "1.0.0", "version": "1.0.0",
"description": "A script to download attachments from an RSS feed.", "description": "A Python application to download attachments from an RSS feed.",
"main": "index.py", "main": "index.py",
"scripts": { "scripts": {
"start": "python index.py" "start": "python3 index.py"
}, },
"devDependencies": { "dependencies": {
"feedparser": "^2.2.10", "feedparser": "^6.0.2",
"requests": "^0.3.0" "requests": "^2.25.1"
} }
} }