diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2013-12-27 10:05:32 +0100 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2013-12-27 10:05:32 +0100 |
commit | 395d5491644d89968941425814729e2b672bce3d (patch) | |
tree | 2f75dacf493cbf80e01425952cabe4856473fbfb /pyaggr3g470r | |
parent | No need to test explicitly if the article is already in the database since th... (diff) | |
download | newspipe-395d5491644d89968941425814729e2b672bce3d.tar.gz newspipe-395d5491644d89968941425814729e2b672bce3d.tar.bz2 newspipe-395d5491644d89968941425814729e2b672bce3d.zip |
Better management of exceptions.
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r-- | pyaggr3g470r/feedgetter.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/pyaggr3g470r/feedgetter.py b/pyaggr3g470r/feedgetter.py index cfad4f0d..13973d7b 100644 --- a/pyaggr3g470r/feedgetter.py +++ b/pyaggr3g470r/feedgetter.py @@ -32,6 +32,7 @@ import feedparser import requests from urlparse import urlparse from BeautifulSoup import BeautifulSoup +from mongoengine.queryset import NotUniqueError from datetime import datetime import models @@ -117,7 +118,8 @@ class FeedGetter(object): description = BeautifulSoup(description, "html.parser").decode() article_title = BeautifulSoup(article.title, "html.parser").decode() except Exception as E: - #pyaggr3g470r_log.error("Problem when sanitizing the content of the feed: " + feed.link) + pyaggr3g470r_log.error("Problem when sanitizing the content of the article %s (%s)" \ + % (article_title, real_url)) article_title = article.title try: @@ -130,8 +132,10 @@ class FeedGetter(object): try: article.save() pyaggr3g470r_log.info("New article %s (%s) added." % (article_title, real_url)) + except NotUniqueError: + pyaggr3g470r_log.error("Article %s (%s) already in the database." % (article_title, real_url)) + continue except Exception as e: - # article already retrieved (continue with the nex article) pyaggr3g470r_log.error("Error when inserting article in database: " + str(e)) continue articles.append(article) |