Gmail to SQLite

https://news.ycombinator.com/rss Hits: 6
Summary

Gmail to SQLite This is a script to download emails from Gmail and store them in a SQLite database for further analysis. I find it extremely useful to have all my emails in a database to run queries on them. For example, I can find out how many emails I received per sender, which emails take the most space, and which emails from which sender I never read. Installation Clone this repository: git clone https://github.com/marcboeker/gmail-to-sqlite.git . Install the requirements: pip install -r requirements.txt Create a Google Cloud project here. Open Gmail in API & Services and activate the Gmail API. Open the OAuth consent screen and create a new consent screen. You only need to provide a name and contact data. Next open Create OAuth client ID and create credentials for a Desktop app . Download the credentials file and save it under credentials.json in the root of this repository. Here is a detailed guide on how to create the credentials: https://developers.google.com/gmail/api/quickstart/python#set_up_your_environment. Usage Sync all emails Run the script: python main.py sync --data-dir path/to/your/data where --<data-dir> is the path where all data is stored. This creates a SQLite database in <data-dir>/messages.db and stores the user credentials under <data-dir>/credentials.json . After the script has finished, you can query the database using, for example, the sqlite3 command line tool: sqlite3 <data-dir>/messages.db . You can run the script again to sync all new messages. Provide --full-sync to force a full sync. However, this will only update the read status, the labels, and the last indexed timestamp for existing messages. Sync a single message python main.py sync-message --data-dir path/to/your/data --message-id <message-id> Commandline parameters usage: main.py [-h] [--data-dir DATA_DIR] [--update] {sync, sync-message} Main commands: sync Sync emails from Gmail to the database. sync-message Sync a single message from Gmail to the database. --data-dir DATA_DI...

First seen: 2025-05-10 06:17

Last seen: 2025-05-10 11:18