-
Notifications
You must be signed in to change notification settings - Fork 111
Open
Labels
Description
Hello... I'm using your library and I don't know why but my program randomly freezes sometimes. My program is pretty simple and is pretty much just copying the code sample you provide @https://twittersearch.readthedocs.org/en/latest/index.html (actually, your code sample was also freezing when I tried it).
Could it have to do with the version of python I'm using? (2.7.9)
I installed TwitterSearch through pip. I hope its not some deadlock issue.
Here's what I've been running:
from TwitterSearch import *
from time import sleep
try:
tso = TwitterSearchOrder() # create a TwitterSearchOrder object
tso.set_keywords(['#vr', '-RT']) # let's define all words we would like to have a look for
tso.set_language('en') # hell no German, I want English!
tso.set_include_entities(False) # and don't give us all those entity information
# it's about time to create a TwitterSearch object with our secret tokens
ts = TwitterSearch(
consumer_key = 'xxxx',
consumer_secret = 'xxxx',
access_token = 'xxxx',
access_token_secret = 'xxxx'
)
# open file for writing
text_file = open("#vrtest.txt", "w")
# check when to stop
iterations = 0
max_tweets = 100000
# callback fucntion used to check if we need to pause the program
def my_callback_closure(current_ts_instance): # accepts ONE argument: an instance of TwitterSearch
queries, tweets_seen = current_ts_instance.get_statistics()
if queries > 0 and (queries % 2) == 0: # trigger delay every other query
print("\nQueries: " + str(queries) + " now sleeping, 1 minute.\n");
sleep(60) # sleep for 60 seconds
# this is where the fun actually starts :)
for tweet in ts.search_tweets_iterable(tso, callback=my_callback_closure):
current_line = "%s" % ( tweet['text'] )
iterations = iterations + 1
print( "i: " + str(iterations) + " - " + tweet['user']['screen_name'] + " tweeted: " + current_line )
text_file.write(current_line.encode('utf-8', 'ignore') + "\n")
# wait 1 second every 10 tweets
if (iterations % 10 == 0):
print("\nSleeping 1 second.\n")
sleep(1)
if (iterations >= max_tweets):
break
except TwitterSearchException as e: # take care of all those ugly errors if there are some
print(e)
finally:
# close file
text_file.close()