From c888fd0a6337c7cd0939816377abe2ccf4825fae Mon Sep 17 00:00:00 2001 From: saltire sable Date: Wed, 18 Dec 2013 20:47:12 -0500 Subject: [PATCH] [rss] Fix error looking for timestamp on new RSS items; add date format Was throwing an AttributeError on items without an 'updated' value. Added DATEFORMAT as a variable at the top of the module; this could possibly be added as a configuration option. --- rss.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/rss.py b/rss.py index fa3062ddcb..cf3e680468 100644 --- a/rss.py +++ b/rss.py @@ -21,6 +21,7 @@ socket.setdefaulttimeout(10) INTERVAL = 60 * 5 # seconds between checking for new updates +DATEFORMAT = '%b %d %Y %X' # format for timestamp displayed on new items def setup(bot): @@ -434,12 +435,15 @@ def disable_feed(): if not fp.entries: continue - feed_etag = fp.etag if hasattr(fp, 'etag') else None - feed_modified = fp.modified if hasattr(fp, 'modified') else None + feed_etag = getattr(fp, 'etag', None) + feed_modified = getattr(fp, 'modified', None) entry = fp.entries[0] + # parse published and updated times into datetime objects (or None) entry_dt = (datetime.fromtimestamp(time.mktime(entry.published_parsed)) - if 'published' in entry else None) + if hasattr(entry, 'published_parsed') else None) + entry_update_dt = (datetime.fromtimestamp(time.mktime(entry.updated_parsed)) + if hasattr(entry, 'updated_parsed') else None) # check if article is new, and skip otherwise if (feed.title == entry.title and feed.link == entry.link @@ -471,8 +475,10 @@ def disable_feed(): # print new entry message = u"[\x02{0}\x02] \x02{1}\x02 {2}".format( colour_text(feed.name, feed.fg, feed.bg), entry.title, entry.link) - if entry.updated: - message += " - " + entry.updated + # append update time if it exists, or published time if it doesn't + timestamp = entry_update_dt or entry_dt + if timestamp: + message += " - {0}".format(timestamp.strftime(DATEFORMAT)) bot.msg(feed.channel, message) conn.close()