Comments (9)
If you use r's iterator I don't see the necessity of a stop function. Maybe you have something else in mind. Can you show me a code example of how you would use r.stop()
if there were such a method?
from twitterapi.
r = api.request('statuses/filter', {'track':TRACK_TERM})
for item in r.get_iterator():
if stop(item):
break
process_tweet(item)
def stop(item):
if 'code' in item and item['code'] is 88:
print "Rate limit exceeded."
return True
else:
return False
from twitterapi.
The reason I want to stop the api.request
is because I want to be able to change the search term on the fly, maybe I'm trying to solve that problem the wrong way?
from twitterapi.
It really depends on what you want to do. For example, you could get a tweet and change the request and get another tweet this way:
r = api.request('statuses/filter', {'track':TRACK_TERM1})
tweet = next(r.get_iterator())
print tweet['text']
r = api.request('statuses/filter', {'track':TRACK_TERM2})
tweet = next(r.get_iterator())
print tweet['text']
You can see from this example, which uses next
, and the previous example, which uses a for
loop, there is no starting and stopping of the stream. The request method returns an object which represents the stream you requested. The iterator lets you grab one item from that stream at a time. You can grab as many items as you like, and you can stop grabbing items whenever you like.
I hope that clarifies something.
from twitterapi.
If I understand your example it allows me to search for many things at the same time?
What I would like to do is to stop tracking the old one and start tracking the new one. Hard coding the amount of times I can change the search term is not an option either. Best would be if I could just replace the old search term with the new one.
from twitterapi.
I think you are misunderstanding. The last example does not do a simultaneous search. It does exactly what you said:
- tracks one term
- replaces the the term with a new one
- tracks a second term
from twitterapi.
Yes, I am pretty sure there is something here I do not understand.
My code first looks like this:
r = api.request('statuses/filter', {'track': track_term})
for item in r:
print(item['text'] if 'text' in item else item)
That works fine. But later in the script I change the value of track_term
and replace r
. Like this:
track_term = 'pizza'
r = api.request('statuses/filter', {'track': track_term})
The old for loop still outputs the results from the first track_term
.
from twitterapi.
That sounds right, because the for
loop never ends. And, as you said in your first post, you need a way to stop the stream. Maybe what you do not realize is that even if you could call r.stop()
it would not be effective for you. You probably would call it just before you wanted to set the new search term; however, your program would still be in the for
loop and never reach r.stop()
. This is why there is no point in having a stop method.
What I suggest is this. First, ask yourself what is the condition you want the for
loop to stop. You have not specified that in this thread. Second, use that condition in the stop function example I provided in my second post.
from twitterapi.
It feels like I am looking at this in the wrong way. What you say makes sense, but since I do not have that much experience with Python I am having a hard time implementing it.
I will close this thread now but I am more than happy with all the help you have given me. Thank you very much and keep up the good work!
from twitterapi.
Related Issues (20)
- Wrong documentation version on gh-pages HOT 1
- No includes in _RestIterable response without hydration
- lang filtering does not seem to work HOT 1
- Attempting to pull more than 10 tweets with search/tweets HOT 1
- Question: how do I acquire `screen_name` using `author_id`?? HOT 1
- DM Example not working HOT 2
- gracefully handling a stalled stream HOT 51
- Upgrade Ads API to version 10 - Deadline March 31, 2022
- Bearer Token Issue with Academic Access in Twitter API V2 HOT 1
- SUBSCRIPTION ENDPOINT NOT WORKING HOT 2
- `expansions` does not work with `author_id` HOT 2
- Twitter Ads API version 10 deprecation - End of life date September 29, 2022
- Add support for `/users/:id/bookmarks` endpoint
- Add support for OAuth2 authentication with access_tokens HOT 1
- Not able to create Webhook with Twitter HOT 2
- Request method fails to attach additional metadata HOT 2
- Authenticating error (api_version='2') HOT 8
- Can't attach media V2 HOT 2
- Publish Tweets w/ v2 HOT 3
- OP_NO_TICKET SSL Option no longer supported by Twitter 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 twitterapi.