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
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)
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', ' '))
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
conn.privmsg(
evt.source().split('!')[0],
"%sHi! I'm Twitterbot! you can (follow "
- + "<twitter_name>) to make me follow a user or "
- + "(unfollow <twitter_name>) to make me stop." %
+ "<twitter_name>) to make me follow a user or "
+ "(unfollow <twitter_name>) to make me stop." %
get_prefix())
except Exception:
traceback.print_exc(file=sys.stderr)