Skip to content

Instantly share code, notes, and snippets.

@dieseltravis
Created November 26, 2022 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dieseltravis/3f972fb7d53192e5d124af9e904a22f9 to your computer and use it in GitHub Desktop.
Save dieseltravis/3f972fb7d53192e5d124af9e904a22f9 to your computer and use it in GitHub Desktop.
TimelineListener class using StreamListener from Mastodon.py
#!/usr/bin/python3
from mastodon import Mastodon, StreamListener
# etc...
class TimelineListener(StreamListener):
def __init__(self):
print("Listener created.")
def on_notification(self, notification):
print("Notification: " + notification['type'])
if notification['type'] == 'follow':
on_follow(_client, notification['account'])
def on_update(self, update):
print("Update: " + update['visibility'])
if update['visibility'] == 'public':
on_timeline(_client, update)
if update['visibility'] == 'direct':
on_message(_client, update)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment