def lists(db_path, identifiers, attach, sql, auth, ids, members): "Fetch lists belonging to specified users" auth = json.load(open(auth)) session = utils.session_for_auth(auth) db = utils.open_database(db_path) identifiers = utils.resolve_identifiers(db, identifiers, attach, sql) # Make sure we have saved these users to the database for batch in utils.fetch_user_batches(session, identifiers, ids): utils.save_users(db, batch) first = True for identifier in identifiers: if ids: kwargs = {"user_id": identifier} else: kwargs = {"screen_name": identifier} fetched_lists = utils.fetch_lists(db, session, **kwargs) if members: for new_list in fetched_lists: utils.fetch_and_save_list( db, session, new_list["full_name"].rstrip("@") ) if not first: # Rate limit is one per minute first = False time.sleep(60)
def go(update): for users_chunk in utils.fetch_user_list_chunks( session, user_id, screen_name, noun=noun ): fetched.extend(users_chunk) utils.save_users(db, users_chunk, **save_users_kwargs) update(len(users_chunk))
def users_lookup(db_path, identifiers, attach, sql, auth, ids): "Fetch user accounts" auth = json.load(open(auth)) session = utils.session_for_auth(auth) db = utils.open_database(db_path) identifiers = utils.resolve_identifiers(db, identifiers, attach, sql) for batch in utils.fetch_user_batches(session, identifiers, ids): utils.save_users(db, batch)
def follow(db_path, identifiers, attach, sql, ids, auth, verbose): "Experimental: Follow these Twitter users and save tweets in real-time" auth = json.load(open(auth)) session = utils.session_for_auth(auth) db = utils.open_database(db_path) identifiers = utils.resolve_identifiers(db, identifiers, attach, sql) # Make sure we have saved these users to the database for batch in utils.fetch_user_batches(session, identifiers, ids): utils.save_users(db, batch) # Ensure we have user IDs, not screen names if ids: follow = identifiers else: follow = utils.user_ids_for_screen_names(db, identifiers) # Start streaming: for tweet in utils.stream_filter(session, follow=follow): if verbose: print(json.dumps(tweet, indent=2)) with db.conn: utils.save_tweets(db, [tweet])