Skip to content

Commit

Permalink
Merge pull request sopel-irc#395 from saltire/master
Browse files Browse the repository at this point in the history
[rss] Fix error looking for timestamp on new RSS items; add date format
  • Loading branch information
embolalia committed Dec 24, 2013
2 parents 72ddce6 + c888fd0 commit 2e4b20f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 2e4b20f

Please sign in to comment.