def load_user_and_the_people_they_follow(creds, user_id, postgres_handle): remaining_hits_threshold = 10 api_handle = creds.api_handle root_user = creds.root_user is_root_user = False if root_user.id == user_id: is_root_user = True # if is_root_user and 'root_user.is_fake_user': # return None remaining_hits, reset_time = get_rate_limit_status(api_handle) if remaining_hits < remaining_hits_threshold: raise Exception("%s: remaining_hits less than threshold!" % root_user.screen_name) try: api_user = api_handle.get_user(user_id=user_id) except TweepError, ex: print "%s: api_handle.get_user(%s) got a TweepError %s" % ( root_user.screen_name, user_id, ex) if 'Sorry, that page does not exist' in str( ex) or 'User has been suspended' in str(ex): print 'setting caused_an_error' model_user = TwitterUser.get_by_id(user_id, postgres_handle) if not model_user: properties = {'id': user_id, 'screen_name': user_id} model_user = TwitterUser(postgres_handle=postgres_handle, **properties) model_user.save() postgres_handle.connection.commit() model_user.caused_an_error = datetime.now() model_user.save() postgres_handle.connection.commit() return None