···53535454Twitter's API only returns up to around 3,200 tweets for most user accounts, but you may find that it returns all available tweets for your own user account.
55555656+You can use `--since` to retrieve every tweet since the last time you imported for that user, or `--since_id=xxx` to retrieve every tweet since a specific tweet ID.
5757+5658## Retrieve accounts in bulk
57595860If you have a list of Twitter screen names (or user IDs) you can bulk fetch their fully inflated Twitter profiles using the `users-lookup` command:
+29-4
twitter_to_sqlite/cli.py
···178178@click.option("--stop_after", type=int, help="Only pull this number of recent tweets")
179179@click.option("--user_id", help="Numeric user ID")
180180@click.option("--screen_name", help="Screen name")
181181-def user_timeline(db_path, auth, stop_after, user_id, screen_name):
181181+@click.option(
182182+ "--since",
183183+ is_flag=True,
184184+ default=False,
185185+ help="Pull tweets since last retrieved tweet",
186186+)
187187+@click.option(
188188+ "--since_id", type=str, default=False, help="Pull tweets since this Tweet ID"
189189+)
190190+def user_timeline(db_path, auth, stop_after, user_id, screen_name, since, since_id):
182191 "Save tweets posted by specified user"
192192+ if since and since_id:
193193+ raise click.ClickException("Use either --since or --since_id, not both")
183194 auth = json.load(open(auth))
184195 session = utils.session_for_auth(auth)
185196 profile = utils.get_profile(session, user_id, screen_name)
186197 db = sqlite_utils.Database(db_path)
198198+ expected_length = profile["statuses_count"]
199199+200200+ if since or since_id:
201201+ expected_length = None
202202+203203+ if since:
204204+ try:
205205+ since_id = db.conn.execute(
206206+ "select max(id) from tweets where user = ?", [profile["id"]]
207207+ ).fetchall()[0][0]
208208+ print("since = ", since_id)
209209+ except IndexError:
210210+ pass
211211+187212 with click.progressbar(
188188- utils.fetch_user_timeline(session, user_id, screen_name, stop_after),
189189- length=profile["statuses_count"],
213213+ utils.fetch_user_timeline(session, user_id, screen_name, stop_after, since_id=since_id),
214214+ length=expected_length,
190215 label="Importing tweets",
191216 show_pos=True,
192217 ) as bar:
···226251def home_timeline(db_path, auth, since, since_id):
227252 "Save tweets from timeline for authenticated user"
228253 if since and since_id:
229229- raise click.ClickException("Use either --since or --since_id, not both ")
254254+ raise click.ClickException("Use either --since or --since_id, not both")
230255 auth = json.load(open(auth))
231256 session = utils.session_for_auth(auth)
232257 profile = utils.get_profile(session)