···128128129129The underlying Twitter APIs have a rate limit of 15 requests every 15 minutes - though they do return up to 5,000 IDs in each call. By default both of these subcommands will wait for 61 seconds between API calls in order to stay within the rate limit - you can adjust this behaviour down to just one second delay if you know you will not be making many calls using `--sleep=1`.
130130131131+## Retrieving tweets from your home timeline
132132+133133+The `home-timeline` command retrieves up to 800 tweets from the home timeline of the authenticated user - generally this means tweets from people you follow.
134134+135135+ $ twitter-to-sqlite home-timeline twitter.db
136136+ Importing timeline [#################--------] 591/800 00:01:14
137137+138138+The tweets are stored in the `tweets` table, and a record is added to the `timeline_tweets` table noting that this tweet came in due to being spotted in the timeline of your user.
139139+140140+You can then view your timeline in Datasette using the following URL:
141141+142142+`/tweets/tweets?_where=id+in+(select+tweet+from+[timeline_tweets])&_sort_desc=id&_facet=user`
143143+144144+This will filter your tweets table to just tweets that appear in your timeline, ordered by most recent first and use faceting to show you which users are responsible for the most tweets.
145145+131146## Providing input from a SQL query with --sql and --attach
132147133148This option is available for some subcommands - run `twitter-to-sqlite command-name --help` to check.
+43
twitter_to_sqlite/cli.py
···198198 utils.save_tweets(db, chunk)
199199200200201201+@cli.command(name="home-timeline")
202202+@click.argument(
203203+ "db_path",
204204+ type=click.Path(file_okay=True, dir_okay=False, allow_dash=False),
205205+ required=True,
206206+)
207207+@click.option(
208208+ "-a",
209209+ "--auth",
210210+ type=click.Path(file_okay=True, dir_okay=False, allow_dash=True, exists=True),
211211+ default="auth.json",
212212+ help="Path to auth.json token file",
213213+)
214214+def home_timeline(db_path, auth):
215215+ "Save tweets from timeline for authenticated user"
216216+ auth = json.load(open(auth))
217217+ session = utils.session_for_auth(auth)
218218+ profile = utils.get_profile(session)
219219+ db = sqlite_utils.Database(db_path)
220220+ with click.progressbar(
221221+ utils.fetch_home_timeline(session),
222222+ length=800,
223223+ label="Importing timeline",
224224+ show_pos=True,
225225+ ) as bar:
226226+ # Save them 100 at a time
227227+ def save_chunk(db, chunk):
228228+ utils.save_tweets(db, chunk)
229229+ # Record who's timeline they came from
230230+ db["timeline_tweets"].upsert_all([{
231231+ "user": profile["id"],
232232+ "tweet": tweet["id"]
233233+ } for tweet in chunk], pk=("user", "tweet"), foreign_keys=("user", "tweet"))
234234+ chunk = []
235235+ for tweet in bar:
236236+ chunk.append(tweet)
237237+ if len(chunk) >= 100:
238238+ save_chunk(db, chunk)
239239+ chunk = []
240240+ if chunk:
241241+ save_chunk(db, chunk)
242242+243243+201244@cli.command(name="users-lookup")
202245@click.argument(
203246 "db_path",