Fixing streaming, fixes #144 #187
No reviewers
Labels
No labels
Bug
Enhancement
Feature Suggestion
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: code/twython#187
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "streaming"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #144
Alright @ryanmcgrath here it is. :D
Something I want your opinion on though:
Right now I have it so they have to use the streaming API like this:
Using TwythonStreamer to make calls
Do we want to enable the core
Twythonclass to have streaming access?So the user can do
To me adding it to core
Twythonmight end up getting a bit messing.. having to pass stream_config and all, but let me know if you think you'd want it available from that class!Also, do you think we should keep all streaming stuff in
streaming.pyor make a folder
streaminghandlers.pyapi.pytypes.pyHmmm, this is getting really good. The only thing is my original example/pseudo-code was one less deeper in terms of... let's say allocation level. e.g:
vs
My original point was that if we already have a subclass situation going on, we may as well just have them inherit from the handler itself, then instantiate that. Callbacks would basically be abstract methods on the class that a user would opt-in to.
In terms of it crossing streams (lol...) with Twython core, I'd just keep them separate for now - most of the use cases that I see have them fairly separate. Only thing that really exists between the two is the tokens.
As far as the code itself, what I'm looking at seems pretty top notch and I'm overall really impressed with the quality. I think the only thing I'd be concerned about at this point is what the experience is for end-users, ala the above.
Well, not all streams take the same thing, that's why I kept the parameters being passed to each function instead of at class level. (Also, to keep it a bit consistent with
Twythoncore.Twython.updateStatus(status='blah')Speaking of keeping it consistent. I did diverge though by doing
TwythonStreamer.statuses.filter(track='twitter')instead of
TwythonStreamer.statuses_filter(track='twitter)I was going to do it the second way even though all core
Twythonmethods are camelCasedi.e.
Twython.updateStatusWithMediabut if you did want me to change it fromstatuses.filtertostatuses_filterI could but just didn't want to dostatusesFilterin the case that we move forward with #186Mmm, I see your point about the args. My example in my earlier comment has
follow,replies, and the like on a Class-level; that's totally fine the way you're doing it. I guess my biggest hangup would be passing the instantiatedMyHandlerto an instantiation ofTwythonStreamer.I think
MyHandlerbeing a subclass ofTwythonStreamerwould just be cleaner API-wise, and potentially less confusing to someone new to the library. Part of the userbase of this library tends to be people new to programming, after all.So, you want something like this
streaming.pyexample code
That is... exactly what I was getting at, wow. Nice job.
What do you think, after seeing it? The aim is to have it be as straight-forward and clear-cut as possible, which I think this does - it's essentially async code, which... well, I don't really think Python does a great job of enabling, but this approach is grok-able at a glance which I think does wonders.
Yeah, that's fine. The only gripe I have is that I think the Handling is separate from the actual Streaming.. but it is kind of weird passing the Handler instance to the streamer -- so I'm fine integrating the handling methods into the Streamer. I'll prob. fix this tomorrow!
Orrrrr... I just got it done. haha. Everything looks kosher to me.
Last thing before I merge and push something tomorrow..
What do you think about the file structure for streaming?
Should I do like I said and do:
streaming__init__.pyapi.pytypes.pyOr just keep everything in
streaming.py?I would personally separate it, because it's easier to grok for new people, but that's also something we can refine if we need to down the road. Take your pick, I'm fine with either.
Nice job!
I moved it into it's own folder! I'll merge and push to PyPi tomorrow.