twitools/twitools/streaming.py
2017-03-23 14:18:52 +01:00

23 lines
669 B
Python

import dbtools, tweepy
class BotStreamListener(tweepy.StreamListener):
def __init__(self, bot, cid):
self.bot = bot
self.cid = cid
def on_status(self, status):
db = dbtools.dbHelper()
try:
db.executeQuery("SELECT MAX(nr) FROM timelines WHERE cid = %i;" % self.cid)
i = int(db.getNext()[0]) + 1
except:
i = 1
db.executeQuery("INSERT INTO timelines VALUES(%i, %i, %i);" % (self.cid, i, status.id))
self.bot.sendMessage(chat_id=self.cid, text="Tweet %i:\n%s (@%s) at %s:\n%s" % (i, status.author.name, status.author.screen_name, status.created_at, html.unescape(status.text)))
def on_error(self, status):
if status == 420:
return False