Browse Source

try to correct stream problem

v1.2
Dryusdan 2 years ago
parent
commit
1fe24cb0e3
3 changed files with 21 additions and 16 deletions
  1. +1
    -0
      .gitignore
  2. BIN
      TootHTMLParser.pyc
  3. +20
    -16
      bot.py

+ 1
- 0
.gitignore View File

@ -2,3 +2,4 @@ secrets/*
secrets/secrets.txt
config.txt
__pycache__/*
TootHTMLParser.pyc

BIN
TootHTMLParser.pyc View File


+ 20
- 16
bot.py View File

@ -11,25 +11,24 @@ from pprint import pprint
# Mastodon Stream Listener defines functions to react when something happens on Mastodon. We inherit it.
class BotListener(StreamListener):
def __init__(self, mastodon):
print("init")
StreamListener.__init__(self)
def __init__(self, mastodon, log):
log.debug("initialisation step")
#StreamListener.__init__(self)
self.mastodon = mastodon
pprint(vars(mastodon.stream_user(StreamListener)))
def handle_mention(self, status):
log.debug('Got a mention!')
self.log = log
super()
#pprint(vars(mastodon.stream_user(StreamListener)))
def on_notification(self, notification):
log.debug("here")
for thread in self.threads:
if(not thread.is_alive()):
logging.info("removing thread" + str(thread))
self.threads.remove(thread)
log.debug("Got a notification!")
#for thread in self.threads:
# if(not thread.is_alive()):
# logging.info("removing thread" + str(thread))
# self.threads.remove(thread)
#We react to mentions only
if(notification['type'] != 'mention'):
log.info("nevermind, it's not a mention")
log.debug("nevermind, it's not a mention")
return
#So there is a toot !
@ -48,6 +47,9 @@ class BotListener(StreamListener):
#If the toot is not in answer to a drawing
answerTo = status["in_reply_to_id"]
def on_update(self, status):
log.debug("update ! ")
def get_parameter( parameter, file_path ):
# Check if secrets file exists
if not os.path.isfile(file_path):
@ -98,6 +100,8 @@ def init_log(log_filepath):
stream_handler.setLevel(logging.DEBUG)
log.addHandler(stream_handler)
return log
def init_mastodon(config, secrets):
uc_client_id = get_parameter("client_id", secrets)
uc_client_secret = get_parameter("client_secret", secrets)
@ -114,10 +118,10 @@ def init_mastodon(config, secrets):
def run(mastodon, log):
pprint(log)
log.info("Start streaming")
listener = BotListener(mastodon, logging)
mastodon.stream_user(listener)
#post_img(mastodon, "NSFW", 1)
listener = BotListener(mastodon, log)
mastodon.stream_public(listener)
def main():
config_file = "config.txt"


Loading…
Cancel
Save