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

@ -11,10 +11,18 @@ def download_attachment(url, filename):
else:
print(f"Failed to download {url}")
def create_downloads_folder():
downloads_folder = "Downloads"
if not os.path.exists(downloads_folder):
os.makedirs(downloads_folder)
print(f"Created folder: {downloads_folder}")
def main():
feed_url = input("Enter the RSS feed URL: ")
num_entries = int(input("Enter the number of entries to process: "))
create_downloads_folder()
feed = feedparser.parse(feed_url)
for i, entry in enumerate(feed.entries[:num_entries]):
@ -22,7 +30,7 @@ def main():
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)
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",
"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"
}
}