second attempt
This commit is contained in:
parent
ccbc7955af
commit
55cff8e3e3
20
index.py
20
index.py
|
|
@ -1,8 +1,8 @@
|
|||
import feedparser
|
||||
import os
|
||||
import requests
|
||||
import os
|
||||
import requests
|
||||
|
||||
def download_attachment(url, filename):
|
||||
def download_attachment(url, filename):
|
||||
response = requests.get(url)
|
||||
if response.status_code == 200:
|
||||
with open(filename, 'wb') as f:
|
||||
|
|
@ -11,10 +11,18 @@ def download_attachment(url, filename):
|
|||
else:
|
||||
print(f"Failed to download {url}")
|
||||
|
||||
def main():
|
||||
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__":
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
14
package.json
14
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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue