add error handling
This commit is contained in:
parent
b3379086e9
commit
e5f90f79d1
1 changed files with 12 additions and 9 deletions
|
|
@ -31,8 +31,7 @@ def log(text, force = False):
|
||||||
|
|
||||||
# Print error message and exit
|
# Print error message and exit
|
||||||
def error(text):
|
def error(text):
|
||||||
print('{} - ERROR - {}'.format(datetime.now().strftime('%d.%m %H:%M'), text))
|
print('{} E {}'.format(datetime.now().strftime('%d.%m %H:%M'), text))
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
# Print spiderss logo
|
# Print spiderss logo
|
||||||
|
|
@ -118,6 +117,7 @@ def update_feed(feed):
|
||||||
articles = get_articles(feed['url'])
|
articles = get_articles(feed['url'])
|
||||||
threshold_date = datetime.now() - timedelta(days = max_age)
|
threshold_date = datetime.now() - timedelta(days = max_age)
|
||||||
for a in articles:
|
for a in articles:
|
||||||
|
try:
|
||||||
date = datetime.fromtimestamp(mktime(a.published_parsed))
|
date = datetime.fromtimestamp(mktime(a.published_parsed))
|
||||||
if date > threshold_date:
|
if date > threshold_date:
|
||||||
filename = get_filename(date, a.title)
|
filename = get_filename(date, a.title)
|
||||||
|
|
@ -125,6 +125,8 @@ def update_feed(feed):
|
||||||
text = get_article_text(a)
|
text = get_article_text(a)
|
||||||
write_to_file(os.path.join(feedpath_new, filename), text)
|
write_to_file(os.path.join(feedpath_new, filename), text)
|
||||||
log(' added article "{}"'.format(a.title))
|
log(' added article "{}"'.format(a.title))
|
||||||
|
except Exception as e:
|
||||||
|
error(' while parsing article "{}: {}"'.format(a.title, e))
|
||||||
|
|
||||||
|
|
||||||
# Delete articles older than max_age
|
# Delete articles older than max_age
|
||||||
|
|
@ -157,6 +159,7 @@ def load_config(filepath):
|
||||||
feeds = config['feed']
|
feeds = config['feed']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error('while parsing config: {}'.format(e))
|
error('while parsing config: {}'.format(e))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
# Initialize spiderss
|
# Initialize spiderss
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue