twitools/bottools/thread.py

42 lines
1.1 KiB
Python
Raw Normal View History

import bottools.methods, dbtools, logging, threading, time, twitools
class BotStreamThread(threading.Thread):
def __init__(self, bot, cid, ato, searchstring = None):
threading.Thread.__init__(self)
self.bot = bot
self.cid = cid
self.ato = ato
self.ase = dbtools.dbHelper().aseByAto(ato)
self.two = twitools.twObject(ato=ato, ase=self.ase)
self.searchstring = searchstring or "@%s" % self.two.whoami().strip("@")
self.lm = self.two.getLastMention()
self.stop = False
def run(self):
while not self.stop:
try:
for status in self.two.getMentions(self.lm):
try:
bottools.methods.tweetMessage(status, self.cid, self.bot, notified = self.ato)
self.lm = status.id
except Exception as e:
logging.exception(e)
except Exception as e:
logging.exception(e)
for i in range(0, 89):
if not self.stop:
time.sleep(1)
def disconnect(self):
self.stop = True
def BotStreamListener(bot, cid, ato, searchstring = None):
obj = bottools.thread.BotStreamThread(bot, cid, ato, searchstring)
obj.start()
return obj