X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/85681608c592c7e3eb6cc75367dc0cdd2ea953dd..a5e40197cf272175a8bc4aa39d4c5b6e545c751c:/twitter/ircbot.py?ds=sidebyside diff --git a/twitter/ircbot.py b/twitter/ircbot.py index 6819a88..c1bae08 100644 --- a/twitter/ircbot.py +++ b/twitter/ircbot.py @@ -46,7 +46,8 @@ IRC_REGULAR = chr(0x0f) import sys import time -from dateutil.parser import parse +from datetime import datetime, timedelta +from email.utils import parsedate from ConfigParser import SafeConfigParser from heapq import heappop, heappush import traceback @@ -153,12 +154,12 @@ class TwitterBot(object): self.sched = Scheduler( (SchedTask(self.process_events, 1), SchedTask(self.check_statuses, 120))) - self.lastUpdate = time.gmtime() + self.lastUpdate = (datetime.utcnow() - timedelta(minutes=10)).utctimetuple() def check_statuses(self): debug("In check_statuses") try: - updates = self.twitter.statuses.friends_timeline() + updates = reversed(self.twitter.statuses.friends_timeline()) except Exception, e: print >> sys.stderr, "Exception while querying twitter:" traceback.print_exc(file=sys.stderr) @@ -167,7 +168,7 @@ class TwitterBot(object): nextLastUpdate = self.lastUpdate debug("self.lastUpdate is %s" % self.lastUpdate) for update in updates: - crt = parse(update['created_at']).utctimetuple() + crt = parsedate(update['created_at']) if (crt > nextLastUpdate): text = (htmlentitydecode( update['text'].replace('\n', ' ')) @@ -183,12 +184,8 @@ class TwitterBot(object): IRC_BOLD, update['user']['screen_name'], IRC_BOLD, text.decode('utf-8'))) - debug("tweet has crt %s, updating nextLastUpdate (was %s)" %( - crt, nextLastUpdate, - )) nextLastUpdate = crt - else: - break + debug("setting self.lastUpdate to %s" % nextLastUpdate) self.lastUpdate = nextLastUpdate @@ -209,8 +206,8 @@ class TwitterBot(object): conn.privmsg( evt.source().split('!')[0], "%sHi! I'm Twitterbot! you can (follow " - + ") to make me follow a user or " - + "(unfollow ) to make me stop." % + ") to make me follow a user or " + "(unfollow ) to make me stop." % get_prefix()) except Exception: traceback.print_exc(file=sys.stderr)