-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Streaming not working #348
Comments
I'm kind of confused by this - the tutorial you linked seems to just be... wrong, and I don't think that would have worked in any past version either. What you want to do instead is something like (just from memory, didn't test, might not be 100% correct): from mastodon.streaming import CallbackStreamListener
# ... setup ...
def handle_mention(notification):
if notification.type == "mention":
print(notification.status)
listener = CallbackStreamListener(notification_handler = handle_mention)
mastodon.stream_user(listener) You might also want to look at run_async and reconnect_async if you want the stream to just run forever and reconnect if it loses connection. You can find a full example of how to use the streaming API here: https://github.com/halcy/MastodonpyExamples/blob/bba210623a31d2f148ec4560669d22786e8102e3/01_latency_observatory/latencies.py |
thanks for the feedback and the example, closing as it's not an actual Issue ( : |
Did you get it working? If so, could you tell me if the snippet above was correct? I should probably ask the author of that tutorial to fix it |
hmm not really. Sorry, I should have made a proper test before closing it. I modified your code as follows using public stream: from mastodon.streaming import CallbackStreamListener
# ... setup ...
hashtag="vegan"
def handle_mention(status):
if hashtag in status.content.lower():
print(status.content)
else:
print(status.content)
listener = CallbackStreamListener(notification_handler = handle_mention)
mastodon.stream_public(listener) but it doesn't catch any use of the hashtag, nor in the else statement gives any output. It should be printing every toot in real time, right? i also tried with |
For hashtags, you would want the on_update handler, so you'd want to modify that CallbackStreamListener line like so: listener = CallbackStreamListener(update_handler = handle_mention) That should make your code work and print all the statuses. You can have a look at the docs: https://mastodonpy.readthedocs.io/en/stable/10_streaming.html but maybe that API just is a bit confusing, especially now that there are quite a few events, instead of just like, three, a few versions back. I wonder if we could add some simpler way where all events just go to one function. |
when calling the
mastodon.stream_user(handle_mention)
function as per this tutorialthe following error prompts:
The text was updated successfully, but these errors were encountered: