From c3ada18a3974d21679ecef6fc6e96df35da16a1b Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Fri, 10 Jun 2011 13:57:44 +0200 Subject: Minor improvement: test if the published/update date for the article is present before the data base insertion --- feedgetter.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'feedgetter.py') diff --git a/feedgetter.py b/feedgetter.py index 54183b08..d272fcb1 100755 --- a/feedgetter.py +++ b/feedgetter.py @@ -132,10 +132,15 @@ class FeedGetter(object): description = str(BeautifulSoup(description)) article_title = str(BeautifulSoup(article.title)) + try: + post_date = datetime(*article.updated_parsed[:6]) + except: + post_date = datetime(*article.published_parsed[:6]) + try: # try. Will only success if the article is not already in the data base self.c.execute('insert into articles values (?, ?, ?, ?, ?, ?, ?)', (\ - datetime(*article.updated_parsed[:6]), \ + post_date, \ article_title, \ article.link.encode('utf-8'), \ description, \ @@ -158,9 +163,9 @@ class FeedGetter(object): except sqlite3.IntegrityError: # article already in the data base pass - except: + except Exception, e: # Missing information (updated_parsed, ...) - pass + print e if __name__ == "__main__": -- cgit