odrling / peony-twitter

An asynchronous Twitter API client for Python 3.6+
MIT License
83 stars 4 forks source link

How would I do stuff if a specific user tweeted? #33

Open ShadiestGoat opened 4 years ago

ShadiestGoat commented 4 years ago

Heya! Its just as the title says.. I saw stuff like track.py in the examples, but I can't find more documention on the filter() and how to use that for users ://

odrling commented 4 years ago

Hello there! To do that you have to take a look at Twitter's API documentation. Peony was designed to be able to use any endpoint without needing to create specific methods for each of them. In this case I'm using this API endpoint: https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/api-reference/post-statuses-filter It has a follow parameter that takes a list of user ids, you should be able to use the same parameter in peony:

stream = client.stream.statuses.filter.post(follow=user_id)
ShadiestGoat commented 4 years ago

Heya thanks for responding! Thats really cool, ill give it a try :D

ShadiestGoat commented 4 years ago

Heya! Sorry for the slow response. This does work, obviusly, but is kinda slow. In my bot, it takes the majority of the time (~6 seconds), just to get the tweet. Is there a way to make it faster, or is this the max possible?

odrling commented 4 years ago

I'm not using this library as much as I did before, I would assume that the 6 seconds are just latency introduced by Twitter somehow. Internally it's reading the responses from a stream and I remember it being pretty straightforward so I would find it weird if this latency would come from this lib. If this is 6 seconds after the tweet is sent that sounds fine to me, if this is 6 seconds after your regular twitter client would get it that would be weird.

ShadiestGoat commented 4 years ago

yeah 6 seconds is really not much and its really weird that twitter introduced this ;-; I don't think the lib does it either, lemme google further

odrling commented 4 years ago

I only remember reading about that in this article http://highscalability.com/blog/2013/7/8/the-architecture-twitter-uses-to-deal-with-150m-active-users.html. This is old but I think this is still what Twitter has to deal with today. They have to deliver a lot of tweets all the time to many more users so it takes some time.

EDIT: I hit Ctrl+Enter too quickly :/

ShadiestGoat commented 4 years ago

Dam aa. Yeah, I'm guessing its because of that, and since my twitter dev account is relatively new, I think it may have lower priority..