Comments (5)
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
from mastodon.py.
thanks for the feedback and the example, closing as it's not an actual Issue ( :
from mastodon.py.
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
from mastodon.py.
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 stream_hashtag
using the tag
parameter but with the same result
from mastodon.py.
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.
from mastodon.py.
Related Issues (20)
- Add `offset` parameter for `trending_statuses`
- MastodonVersionError: Version check failed (Need version 1.1.0) HOT 5
- How to get configured character limit of Mastodon instance HOT 5
- Add Citation for Mastodon.py HOT 3
- Update filter methods to 4.x HOT 2
- Unable to Host bot HOT 8
- [question] Keeping async listener connection active? HOT 2
- media_update return Error 404: Record not found HOT 4
- Event on mentioned? HOT 2
- mastodon.account_search not working correctly? HOT 10
- Deprecate visibility parameter value `private` and use `followers_only` instead HOT 3
- module is installed, but missing library stubs or py.typed marker HOT 5
- scopes = ['read', 'write'] is ret, but the generated url sill contains '+follow+push' HOT 6
- OAuth question HOT 2
- TypeError: exceptions must derive from BaseException HOT 3
- [Question] Is there a way to export lists as CSV? HOT 2
- [Question] scheduling posts and replies HOT 2
- content_type is not ignored on incompatible servers HOT 2
- [question] retrieving most recent status for a user HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mastodon.py.