1

The below is an extract from my code from a previous question. The aim of this python code is to create a crawler for Twitter where by I plan to run the code every hour for 60 seconds. I am going to do this over 24 hours for 7 days to look at the trends within Tweets.

Currently this code is running until it is manually ended

import time import threading class listener(StreamListener): def on_data(self, data): try: print data saveFile = open('twitDB.csv','a') saveFile.write(data) saveFile.write('\n') saveFile.close() return True except BaseException, e: print 'failed ondata,' ,str(e) time.sleep(5) def on_error(self, status): print status time.sleep(5) 
3
  • So what is the problem, disregarding the contents of the listener class, what you have would do what you want if you repalces the time.sleep(60) with time.sleep(5) Commented Dec 26, 2013 at 15:43
  • You say “extract” from the code of the previous question when it’s actually mostly unchanged. The question does not seem any different at all—and actually there isn’t a question in what you have written. The previous question gives you enough ideas to work with, so please use those answers to solve it. Commented Dec 26, 2013 at 16:14
  • @poke, you are saying right.I just checked that the guy has asked almost the same question again. Commented Dec 26, 2013 at 16:50

1 Answer 1

1

Put the following code in a running thread other than in which your main code is executing and have a try:

import sys,time now=time.time() while True: end=time.time() total=round(end-now) if total==5: sys.exit(0) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.