From 55cff8e3e30cb2bd216373fa9f6dc5835b28f93a Mon Sep 17 00:00:00 2001 From: PK13274 Date: Tue, 1 Apr 2025 15:02:54 -0500 Subject: [PATCH] second attempt --- index.py | 52 ++++++++++++++++++++++++++++++---------------------- package.json | 14 +++++++------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/index.py b/index.py index 74dd708..18c66f9 100644 --- a/index.py +++ b/index.py @@ -1,28 +1,36 @@ import feedparser -import os -import requests + 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 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: ")) + def create_downloads_folder(): + downloads_folder = "Downloads" + 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]): - 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) + create_downloads_folder() -if __name__ == "__main__": - main() + 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(os.path.join("Downloads", filename), link.href) + + if __name__ == "__main__": + main() diff --git a/package.json b/package.json index 69a3442..4790ecb 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { - "name": "rss-feed-downloader", + "name": "rss-feed-attachment-downloader", "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", "scripts": { - "start": "python index.py" + "start": "python3 index.py" }, - "devDependencies": { - "feedparser": "^2.2.10", - "requests": "^0.3.0" + "dependencies": { + "feedparser": "^6.0.2", + "requests": "^2.25.1" } -} + }