fix: [feed] feed-list tool now checks for feed availability

pull/9098/head
Christophe Vandeplas 2023-05-21 14:15:53 +02:00
parent 8fcf6ae69b
commit 836a551b63
No known key found for this signature in database
GPG Key ID: BDC48619FFDC5A5B
1 changed files with 11 additions and 1 deletions

View File

@ -10,7 +10,7 @@
# Copyright (C) 2023 Christophe Vandeplas
import json
import requests
default_feed = '../../app/files/feed-metadata/defaults.json'
@ -18,10 +18,20 @@ with open(default_feed) as feed_file:
feedlist = json.load(feed_file)
print("Checking feed availability.")
items = []
for feed in feedlist:
output = "- [{}]({}) - {} - feed format: {}".format(feed['Feed']['name'], feed['Feed']['url'],feed['Feed']['provider'],feed['Feed']['source_format'])
items.append(output)
# try to download the feed
headers = {"Range": "bytes=0-0"}
res = requests.get(feed['Feed']['url'], headers=headers)
if (res.status_code >= 200 and res.status_code < 300)\
or res.status_code == 403:
continue
else:
print(f'- Feed {feed["Feed"]["name"]} - returns {res.status_code}')
items = sorted(items, key=lambda s: s.casefold())