this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

get_profile() now saves user to DB

This ensures we don't accidentally fail to create a user record
for the currently authenticated user.

+15 -13
+5 -6
twitter_to_sqlite/cli.py
··· 107 107 # Get the follower count, so we can have a progress bar 108 108 count = 0 109 109 110 - profile = utils.get_profile(session, user_id, screen_name) 110 + profile = utils.get_profile(db, session, user_id, screen_name) 111 111 screen_name = profile["screen_name"] 112 112 user_id = profile["id"] 113 113 ··· 152 152 "Save tweets favorited by specified user" 153 153 auth = json.load(open(auth)) 154 154 session = utils.session_for_auth(auth) 155 - profile = utils.get_profile(session, user_id, screen_name) 156 155 db = sqlite_utils.Database(db_path) 156 + profile = utils.get_profile(db, session, user_id, screen_name) 157 157 with click.progressbar( 158 158 utils.fetch_favorites(session, user_id, screen_name, stop_after), 159 159 label="Importing favorites", ··· 193 193 raise click.ClickException("Use either --since or --since_id, not both") 194 194 auth = json.load(open(auth)) 195 195 session = utils.session_for_auth(auth) 196 - profile = utils.get_profile(session, user_id, screen_name) 197 196 db = sqlite_utils.Database(db_path) 197 + profile = utils.get_profile(db, session, user_id, screen_name) 198 198 expected_length = profile["statuses_count"] 199 199 200 200 if since or since_id: ··· 253 253 raise click.ClickException("Use either --since or --since_id, not both") 254 254 auth = json.load(open(auth)) 255 255 session = utils.session_for_auth(auth) 256 - profile = utils.get_profile(session) 257 256 db = sqlite_utils.Database(db_path) 257 + profile = utils.get_profile(db, session) 258 258 expected_length = 800 259 259 if since and db["timeline_tweets"].exists: 260 260 # Set since_id to highest value for this timeline ··· 534 534 # Make sure this user is saved 535 535 arg_user_id = identifier if ids else None 536 536 arg_screen_name = None if ids else identifier 537 - profile = utils.get_profile(session, arg_user_id, arg_screen_name) 537 + profile = utils.get_profile(db, session, arg_user_id, arg_screen_name) 538 538 user_id = profile["id"] 539 - utils.save_users(db, [profile]) 540 539 args = {("user_id" if ids else "screen_name"): identifier} 541 540 for id_batch in utils.cursor_paginate( 542 541 session, api_url, args, "ids", 5000, sleep
+10 -7
twitter_to_sqlite/utils.py
··· 44 44 return r.headers, r.json() 45 45 46 46 47 - def get_profile(session, user_id=None, screen_name=None): 47 + def get_profile(db, session, user_id=None, screen_name=None): 48 48 if not (user_id or screen_name): 49 - return session.get( 49 + profile = session.get( 50 50 "https://api.twitter.com/1.1/account/verify_credentials.json" 51 51 ).json() 52 - args = user_args(user_id, screen_name) 53 - url = "https://api.twitter.com/1.1/users/show.json" 54 - if args: 55 - url += "?" + urllib.parse.urlencode(args) 56 - return session.get(url).json() 52 + else: 53 + args = user_args(user_id, screen_name) 54 + url = "https://api.twitter.com/1.1/users/show.json" 55 + if args: 56 + url += "?" + urllib.parse.urlencode(args) 57 + profile = session.get(url).json() 58 + save_users(db, [profile]) 59 + return profile 57 60 58 61 59 62 def fetch_timeline(session, url, args, sleep=1, stop_after=None):