try to correct stream bug
This commit is contained in:
parent
983aaf78d2
commit
02b34b8012
18
bot.py
18
bot.py
|
@ -31,12 +31,20 @@ def post_img(mastodon, text, visibility, log, config):
|
|||
mastodon.status_post("", None, media_ids=[media_dict], sensitive=True, visibility='public', spoiler_text="#NSFW")
|
||||
|
||||
class BotListener(StreamListener):
|
||||
|
||||
def __init__(self, mastodon, log):
|
||||
self.mastodon = mastodon;
|
||||
self.log = log;
|
||||
self.log.debug("init success")
|
||||
|
||||
def on_notification(self, notification):
|
||||
print("notif")
|
||||
self.log.debug("notif")
|
||||
|
||||
def on_update(self, status):
|
||||
print("update");
|
||||
self.log.debug("update");
|
||||
|
||||
#def handle_heartbeat():
|
||||
# self.log.debug("heartbeat")
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -53,14 +61,12 @@ def main():
|
|||
if args.img:
|
||||
post_img(mastodon, "NSFW", 1, log, config_file)
|
||||
elif args.stream:
|
||||
print("streaming")
|
||||
stream = BotListener();
|
||||
stream = BotListener(mastodon, log);
|
||||
while True:
|
||||
try:
|
||||
print("listening")
|
||||
log.info("Start listening...")
|
||||
mastodon.stream_user(stream, async=False)
|
||||
except Exception as error:
|
||||
pprint(error);
|
||||
log.warning('General exception caught: ' + str(error))
|
||||
time.sleep(0.5)
|
||||
|
||||
|
|
Reference in New Issue