Python script that integrates with Gmail API and performs some rule based operations on emails.
- Python 3.8 or higher
- pip
- Virtualenv
- Docker
- Google account
In both the below methods, table will automatically be created when the application is run.
This is optional. If you don't have postgres installed on your system, you can use the docker-compose file to setup the database.
This will install the postgres database and pgadmin for easy database management.
docker compose build
docker compose up -d
Username and password for the database are already set in the docker-compose file.
If you already have a postgres database running, you can create a database named and add the database details in the .env
file.
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
- Make a folder named
credentials
in the root directory. - Go to Google Developer Console
- Create a new project.
- Enable Gmail API.
- Create OAuth 2.0 Client ID.
- Download the credentials file and save it as
credentials.json
in thecredentials
folder. - Add the
credentials.json
file path in the.env
file.
- Fetch emails from Gmail and store them in the database.
python email_handler.py
This will open a browser window asking for permission to access your Gmail account. Click on Allow
to give permission.
-
Edit the rule JSON file
rules/email_rules.json
and set the required rules. -
Run the rule based operations on the emails.
python apply_rule.py
pytest --ignore=storage