Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rss] Fix error looking for timestamp on new RSS items; add date format #395

Merged
merged 1 commit into from
Dec 24, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions willie/modules/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()