def handle_lookup_tweet_rate_limiting(): global app_id_look_tweet, twitter_look_tweet while True: print '---------handle_lookup_rate_limiting------------------' try: rate_limit_status = twitter_look_tweet.get_application_rate_limit_status( resources=['statuses']) except TwythonRateLimitError as detail: print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + \ 'Cannot test due to last incorrect connection, change Twitter APP ID', str(detail) twutil.release_app(app_id_look_tweet) app_id_look_tweet, twitter_look_tweet = twutil.twitter_change_auth( app_id_look_tweet) continue except TwythonAuthError as detail: print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + \ 'Author Error, change Twitter APP ID', str(detail) twutil.release_app(app_id_look_tweet) app_id_look_tweet, twitter_look_tweet = twutil.twitter_change_auth( app_id_look_tweet) continue except TwythonError as detail: if 'Twitter API returned a 503' in str(detail): print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + \ '503 ERROE, sleep 30 Sec' time.sleep(30) continue except Exception as detail: # if '110' in str(detail) or '104' in str(detail): print datetime.datetime.now().strftime( "%Y-%m-%d-%H-%M-%S" ) + "\t" + 'Connection timed out, sleep 30 Sec' + str(detail) time.sleep(30) continue # else: # print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + 'user lookup in following snowball Unhandled ERROR, EXIT()', str(detail) # exit(1) reset = float(rate_limit_status['resources']['statuses'] ['/statuses/lookup']['reset']) remaining = int(rate_limit_status['resources']['statuses'] ['/statuses/lookup']['remaining']) # print '------------------------lookup--------------------' # print 'user calls reset at ' + str(reset) # print 'user calls remaining ' + str(remaining) if remaining == 0: print datetime.datetime.now().strftime( "%Y-%m-%d-%H-%M-%S" ) + "\t" + 'Need to wait till next reset time' wait = max(reset - time.time(), 0) if wait < 20: time.sleep(wait) else: twutil.release_app(app_id_look_tweet) app_id_look_tweet, twitter_look_tweet = twutil.twitter_change_auth( app_id_look_tweet) continue else: # print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + 'Ready rate to current query' return remaining
def handle_timeline_rate_limiting(): global timeline_app_id, timeline_twitter print '-------------------handle_timeline_rate_limiting-----------' while True: try: rate_limit_status = timeline_twitter.get_application_rate_limit_status( resources=['statuses']) except TwythonRateLimitError as detail: print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + \ 'Cannot test due to last incorrect connection, change Twitter APP ID', str(detail) twutil.release_app(timeline_app_id) timeline_app_id, timeline_twitter = twutil.twitter_change_auth( timeline_app_id) continue except TwythonAuthError as detail: print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + \ 'Author Error, change Twitter APP ID', str(detail) twutil.release_app(timeline_app_id) timeline_app_id, timeline_twitter = twutil.twitter_change_auth( timeline_app_id) continue except TwythonError as detail: # if 'Twitter API returned a 503' in str(detail): print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + \ '503 ERROE, sleep 30 Sec' + str(detail) time.sleep(30) continue # else: # print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + 'Unhandled ERROR, EXIT()', str(detail) # exit(1) except Exception as detail: print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + \ 'Timeline Unhandled ERROR, EXIT()', str(detail) time.sleep(30) continue # exit(2) reset = float(rate_limit_status['resources']['statuses'] ['/statuses/user_timeline']['reset']) remaining = int(rate_limit_status['resources']['statuses'] ['/statuses/user_timeline']['remaining']) # print 'user calls reset at ' + str(reset) # print 'user calls remaining ' + str(remaining) if remaining == 0: print datetime.datetime.now().strftime( "%Y-%m-%d-%H-%M-%S" ) + "\t" + 'Need to wait till next reset time' wait = max(reset - time.time(), 0) if wait < 20: time.sleep(wait) else: twutil.release_app(timeline_app_id) timeline_app_id, timeline_twitter = twutil.twitter_change_auth( timeline_app_id) continue else: # print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + 'Ready rate to current query' return remaining
def handle_follower_rate_limiting(): global app_id_follower, twitter_follower while True: print '---------handle_follower_rate_limiting------------------' try: rate_limit_status = twitter_follower.get_application_rate_limit_status(resources=['followers']) except TwythonRateLimitError as detail: print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + \ 'Cannot test due to last incorrect connection, change Twitter APP ID', str(detail) twutil.release_app(app_id_follower) app_id_follower, twitter_follower = twutil.twitter_change_auth(app_id_follower) continue except TwythonAuthError as detail: print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + \ 'Author Error, change Twitter APP ID', str(detail) twutil.release_app(app_id_follower) app_id_follower, twitter_follower = twutil.twitter_change_auth(app_id_follower) continue except TwythonError as detail: # if 'Twitter API returned a 503' in str(detail): print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + \ '503 ERROE, sleep 30 Sec', str(detail) time.sleep(30) continue # else: # print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + 'Unhandled ERROR, EXIT()', str(detail) # exit(1) except Exception as detail: # if '110' in str(detail) or '104' in str(detail): print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + \ 'Connection timed out, sleep 30 Sec', str(detail) time.sleep(30) continue # else: # print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + 'handle_follower_rate_limiting Unhandled ERROR, EXIT()', str(detail) # exit(2) reset = float(rate_limit_status['resources']['followers']['/followers/ids']['reset']) remaining = int(rate_limit_status['resources']['followers']['/followers/ids']['remaining']) # print '------------------------following--------------------' # print 'user calls reset at ' + str(reset) # print 'user calls remaining ' + str(remaining) if remaining == 0: print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + 'Need to wait till next reset time' wait = max(reset - time.time(), 0) if wait < 20: time.sleep(wait) else: twutil.release_app(app_id_follower) app_id_follower, twitter_follower = twutil.twitter_change_auth(app_id_follower) continue else: # print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + 'Ready rate to current query' return remaining
def handle_lookup_rate_limiting(): global app_id_look, twitter_look while True: print "---------handle_lookup_rate_limiting------------------" try: rate_limit_status = twitter_look.get_application_rate_limit_status(resources=["users"]) except TwythonRateLimitError as detail: print datetime.datetime.now().strftime( "%Y-%m-%d-%H-%M-%S" ) + "\t" + "Cannot test due to last incorrect connection, change Twitter APP ID", str(detail) twutil.release_app(app_id_look) app_id_look, twitter_look = twutil.twitter_change_auth(app_id_look) continue except TwythonAuthError as detail: print datetime.datetime.now().strftime( "%Y-%m-%d-%H-%M-%S" ) + "\t" + "Author Error, change Twitter APP ID", str(detail) twutil.release_app(app_id_look) app_id_look, twitter_look = twutil.twitter_change_auth(app_id_look) continue except TwythonError as detail: if "Twitter API returned a 503" in str(detail): print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + "503 ERROE, sleep 30 Sec" time.sleep(30) continue except Exception as detail: # if '110' in str(detail) or '104' in str(detail): print datetime.datetime.now().strftime( "%Y-%m-%d-%H-%M-%S" ) + "\t" + "Connection timed out, sleep 30 Sec" + str(detail) time.sleep(30) continue # else: # print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + 'user lookup in following snowball Unhandled ERROR, EXIT()', str(detail) # exit(1) reset = float(rate_limit_status["resources"]["users"]["/users/lookup"]["reset"]) remaining = int(rate_limit_status["resources"]["users"]["/users/lookup"]["remaining"]) # print '------------------------lookup--------------------' # print 'user calls reset at ' + str(reset) # print 'user calls remaining ' + str(remaining) if remaining == 0: print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + "Need to wait till next reset time" wait = max(reset - time.time(), 0) if wait < 20: time.sleep(wait) else: twutil.release_app(app_id_look) app_id_look, twitter_look = twutil.twitter_change_auth(app_id_look) continue else: # print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + 'Ready rate to current query' return remaining
def handle_timeline_rate_limiting(): global timeline_app_id, timeline_twitter print "-------------------handle_timeline_rate_limiting-----------" while True: try: rate_limit_status = timeline_twitter.get_application_rate_limit_status(resources=["statuses"]) except TwythonRateLimitError as detail: print datetime.datetime.now().strftime( "%Y-%m-%d-%H-%M-%S" ) + "\t" + "Cannot test due to last incorrect connection, change Twitter APP ID", str(detail) twutil.release_app(timeline_app_id) timeline_app_id, timeline_twitter = twutil.twitter_change_auth(timeline_app_id) continue except TwythonAuthError as detail: print datetime.datetime.now().strftime( "%Y-%m-%d-%H-%M-%S" ) + "\t" + "Author Error, change Twitter APP ID", str(detail) twutil.release_app(timeline_app_id) timeline_app_id, timeline_twitter = twutil.twitter_change_auth(timeline_app_id) continue except TwythonError as detail: # if 'Twitter API returned a 503' in str(detail): print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + "503 ERROE, sleep 30 Sec" + str(detail) time.sleep(30) continue # else: # print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + 'Unhandled ERROR, EXIT()', str(detail) # exit(1) except Exception as detail: print datetime.datetime.now().strftime( "%Y-%m-%d-%H-%M-%S" ) + "\t" + "Timeline Unhandled ERROR, EXIT()", str(detail) time.sleep(30) continue # exit(2) reset = float(rate_limit_status["resources"]["statuses"]["/statuses/user_timeline"]["reset"]) remaining = int(rate_limit_status["resources"]["statuses"]["/statuses/user_timeline"]["remaining"]) # print 'user calls reset at ' + str(reset) # print 'user calls remaining ' + str(remaining) if remaining == 0: print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + "Need to wait till next reset time" wait = max(reset - time.time(), 0) if wait < 20: time.sleep(wait) else: twutil.release_app(timeline_app_id) timeline_app_id, timeline_twitter = twutil.twitter_change_auth(timeline_app_id) continue else: # print datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + "\t" + 'Ready rate to current query' return remaining