def get_user_following(api, user_id): ''' api: twitter.Api oauth login object user_id: twitter user id as integer return: List of integer ids following the user_id ''' following = get_cache(user_id, 'following', 'csv') if following == None: following = api.GetFriendIDs(user_id = user_id) make_cache(following, user_id, 'following', 'csv') return following
def get_user_lists(api, user_id=None, screen_name=None): ''' api: twitter.Api oauth login object user_id: twitter user id as integer (Optional) screen_name: twitter screen name as string (Optional) return: twitter.user object ''' user_lists = get_cache(user_id, 'list', 'jsonlist') if user_lists == None: user_lists = api.GetListsList(None, user_id=user_id) user_lists = [ulist.AsDict() for ulist in user_lists] make_cache(user_lists, user_id, 'list', 'jsonlist') return user_lists
def get_user_tweets(api, user_id): ''' api: twitter.Api oauth login object user_id: twitter user id as integer return: List of integer ids following the user_id ''' tweets = get_cache(user_id, 'tweets', 'jsonlist') if tweets == None: tweets = api.GetUserTimeline(user_id = user_id, count = 200, trim_user = True) tweets = [tweet.AsDict() for tweet in tweets] make_cache(tweets, user_id, 'tweets', 'jsonlist') return tweets
def get_user_info(api, user_id=None, screen_name=None): ''' api: twitter.Api oauth login object user_id: twitter user id as integer (Optional) screen_name: twitter screen name as string (Optional) return: twitter.user object ''' if user_id: user_info = get_cache(user_id, 'info', 'json') if user_info == None: user_info = api.GetUser(user_id=user_id).AsDict() make_cache(user_info, user_info['id'], 'info', 'json') else: user_info = api.GetUser(screen_name=screen_name).AsDict() make_cache(user_info, user_info['id'], 'info', 'json') return user_info
###################################################################### # Everything starts here ###################################################################### configfilename = current_dir+'/lri_config.json' if len(sys.argv) > 1: configfilename = sys.argv[1] # Try to setup server valid_setup = True try: config = json.loads(open(configfilename).read()) try: ext_cache = cache.make_cache(config) try: db = neorest.neorest(config=config,create_indices=False) except Exception, e: print "UNABLE TO SETUP NEO4J DATABASE!" print traceback.format_exc() valid_setup = False except: print "UNABLE TO SET UP CACHE" valid_setup = False except Exception, e: print "UNABLE TO PARSE CONFIG FILE:",configfilename valid_setup = False if valid_setup: if __name__ == "__main__":