this repo has no description
0
fork

Configure Feed

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

follow command now takes screen names, supports --sql and --ids refs #11

+23 -3
+14 -3
twitter_to_sqlite/cli.py
··· 352 352 type=click.Path(file_okay=True, dir_okay=False, allow_dash=False), 353 353 required=True, 354 354 ) 355 - @click.argument("follow", type=str, required=True, nargs=-1) 356 - @click.option("--verbose", is_flag=True, help="Verbose mode: display every tweet") 355 + @add_identifier_options 356 + @click.option("--ids", is_flag=True, help="Treat input as user IDs, not screen names") 357 357 @click.option( 358 358 "-a", 359 359 "--auth", ··· 361 361 default="auth.json", 362 362 help="Path to auth.json token file", 363 363 ) 364 - def follow(db_path, follow, auth, verbose): 364 + @click.option("--verbose", is_flag=True, help="Verbose mode: display every tweet") 365 + def follow(db_path, identifiers, attach, sql, ids, auth, verbose): 365 366 "Experimental: Follow these Twitter users (numeric user IDs required) and save tweets in real-time" 366 367 auth = json.load(open(auth)) 367 368 session = utils.session_for_auth(auth) 368 369 db = sqlite_utils.Database(db_path) 370 + identifiers = utils.resolve_identifiers(db, identifiers, attach, sql) 371 + # Make sure we have saved these users to the database 372 + for batch in utils.fetch_user_batches(session, identifiers, ids): 373 + utils.save_users(db, batch) 374 + # Ensure we have user IDs, not screen names 375 + if ids: 376 + follow = identifiers 377 + else: 378 + follow = utils.user_ids_for_screen_names(db, identifiers) 379 + # Start streaming: 369 380 for tweet in utils.stream_filter(session, follow=follow): 370 381 if verbose: 371 382 print(json.dumps(tweet, indent=2))
+9
twitter_to_sqlite/utils.py
··· 385 385 fix_streaming_tweet(tweet["retweeted_status"]) 386 386 if "quoted_status" in tweet: 387 387 fix_streaming_tweet(tweet["quoted_status"]) 388 + 389 + 390 + def user_ids_for_screen_names(db, screen_names): 391 + sql = "select id from users where lower(screen_name) in ({})".format( 392 + ", ".join(["?"] * len(screen_names)) 393 + ) 394 + return [ 395 + r[0] for r in db.conn.execute(sql, [s.lower() for s in screen_names]).fetchall() 396 + ]