Stream Mastodon activity into a SQLite database
This script subscribes to the live HTTP feed of public activity on my Mastodon instance and writes the results into SQLite database tables.
It needs sqlite-utils
and httpx
:
pip install sqlite-utils httpx
Then run:
python stream.py stream.db
If you want to point it at a different Mastodon instance you'll need to edit the script!
Here's the schema after I ran it for a while:
% sqlite-utils schema stream.db
CREATE TABLE [update] (
[id] TEXT PRIMARY KEY,
[created_at] TEXT,
[in_reply_to_id] TEXT,
[in_reply_to_account_id] TEXT,
[sensitive] INTEGER,
[spoiler_text] TEXT,
[visibility] TEXT,
[language] TEXT,
[uri] TEXT,
[url] TEXT,
[replies_count] INTEGER,
[reblogs_count] INTEGER,
[favourites_count] INTEGER,
[edited_at] TEXT,
[content] TEXT,
[reblog] TEXT,
[account] TEXT,
[media_attachments] TEXT,
[mentions] TEXT,
[tags] TEXT,
[emojis] TEXT,
[card] TEXT,
[poll] TEXT
);
Unsure why conflicting ids are being inserted, could be edits.
Workaround to keep the script going: