python - How to disconnect the streaming on the exact date & time -



python - How to disconnect the streaming on the exact date & time -

i using python , twythonstreamer stream statuses twitter. currently, setup automatic disconnect counting number of collected tweets below:

first set globally

max_tweets = 8000

then in def on_success(self, tweet) , have code snippet:

if (count >= max_tweets): self.disconnect() homecoming false

how can disconnect stream on exact date , time, let's say, on 'october 12, 2014 00:00:00'

since stream process acts serverforever server (unless pass retry count)

twython/streaming/api.py._request if self.retry_count , (self.retry_count - retry_counter) > 0: time.sleep(self.retry_in) retry_counter += 1 _send(retry_counter)

the way stop process is, self.shutdown in on_success callback when status true or, hard way: wrap stream process, maintain pid or reference ,and kill process (like commented here)

edit: approach of streamer wrapper , caller

class your_streamer(twythonstreamer, process): def __init__(self, ): process.__init__(self) consumer_key, consumer_secret, oauth_token,oauth_secret = '','','','' #your twitter keys super(socialvane_streamer, self).__init__(consumer_key, consumer_secret, oauth_token,oauth_secret) def run (self): keyword_list =[] #the keywords want monitorize if keyword_list: logger.info("start_monitoring, tracking keywords = %s" % ','.join(keyword_list)) self.statuses.filter(track=','.join(keyword_list)) def on_error(self, status_code, data): print status_code # want stop trying info because of error? # uncomment next line! # self.disconnect() def on_success(self, data): if 'text' in data: pass #do need

and thread, can main method or want

stream = your_streamer() if stream.ready(): stream.start() logger.debug("pid %i created" % stream.pid) while not your_stop_condition: import time time.sleep(1000) #some sleep stream.terminate()

python twython

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -