I've been having some troubles using the GetStreamFilter function from the Python-Twitter library.
I have used this code:
import twitter
import time
consumer_key = 'myConsumerKey'
consumer_secret = 'myConsumerSecret'
access_token = 'myAccessToken'
access_token_secret = 'myAccessTokenSecret'
apiTest = twitter.Api(consumer_key,
consumer_secret,
access_token,
access_token_secret)
#print(apiTest.VerifyCredentials())
while (True):
stream = apiTest.GetStreamFilter(None, ['someWord'])
try:
print(stream.next())
except:
print ("No posts")
time.sleep(3)
What I want to do is to fetch new tweets that include the word "someWord", and to do these every three seconds (or every time there's a new one that is published).
You need to create the stream only once and outside the loop.
stream = apiTest.GetStreamFilter(None, ['someWord'])
while True:
for tweet in stream:
print(tweet)
How about replacing your while True with a loop that extracts things out of the stream?
for tweet in apiTest.GetStreamFilter(track=['someWord']):
print tweet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With