def check_for_whitehout(): time = get_fuzzed_time(5, 3) minutes, seconds = divmod(time, 60) hours, minutes = divmod(minutes, 60) out('random time: %sh%sm%ss' % (int(hours), int(minutes), int(seconds))) # Setup and start the threading x = Timer(time, check_for_whitehout) x.daemon = True x.start() mutex.acquire() try: try: wpgwhitehout = t.api.GetSearch(term='#WPGWhitehout', count=30, result_type='recent', lang='en') except Exception as e: err('[Main] Search Failure: %s' % e) wpgwhitehout = [] matches = [] for x in wpgwhitehout: text = x.AsDict()['text'] if (text.lower()[0:2] != 'rt' and x.user.screen_name != 'wpgwhitehout'): matches.append(x) used_id = -1 with open(usedpath, 'r') as f: # There should only be one line used_id = int(f.read().strip()) count = 0 for x in matches: text = x.AsDict()['text'] status_id = x.id screen_name = x.user.AsDict()['screen_name'] try: print status_id print used_id if status_id <= used_id: continue out(text) response = '@%s %s' % (screen_name, random.choice(phrases)) out('Response: %s' % response) if not dry_run: t.api.PostUpdate(response, in_reply_to_status_id=status_id) # Write used id to file with open(usedpath, 'w') as f: f.write('%s' % status_id) except Exception, e: err('PostUpdate Exception: %s' % e) out('') count += 1 if count == limit: break finally: mutex.release()