This is a toy project I made to notify my outrigger team when the Dragon Zone community center opens the boat sign up sheet for the week. It tracks a Google sheet and sends an email notification when the sign up tab is unlocked.
This program runs on AWS lambda, which is periodically triggered by CloudWatch Events.
Inputs:
- Google Sheet API - fetch the latest spreadsheet.
- Amazon S3 - fetch the previous spreadsheet snapshot.
Outputs:
- Amazon S3 - store the latest spreadsheet snapshot.
- Amazon SES - service for sending emails.
- Amazon CloudWatch Logs - logging service for debugging.
$ mkdir -p ~/workspace/ && cd ~/workspace
$ git clone https://github.com/tvhong/ocgull.git
The below are my usual setup, which uses pyenv and pyenv-virtualenv wrapper.
Feel free to use your favorite tool for creating virtual env.
# Install pyenv and pyenv-virtualenv with Homebrew.
$ brew install pyenv pyenv-virtualenv
# Create virtualenv `ocgull` based off Python v3.7.1
$ pyenv install 3.7.1 # Install Python 3.7.1 to pyenv
$ pyenv virtualenv 3.7.1 ocgull
# Activate the virtual environment
$ pyenv activate ocgull
$ pyenv which python # Should print .pyenv/versions/ocgull/bin/python
$ python --version # Make sure it's 3.7.1
# Install dependencies
$ cd ~/workspace/ocgull/ && pip install -r requirements.txtTip: You probably want to always activate ocgull virtualenv when accessing
the project directory. For pyenv, this can be achieved with:
$ cd ~/workspace/ocgull && pyenv local ocgullSee https://developers.google.com/sheets/api/guides/authorizing#APIKey
Assuming you're in project repo and activated virtual env, this should fetch the data from a test spreadsheet and print out the result in stdout.
$ GCP_API_KEY=<api-key-obtained-above> ./src/infra/run.pyRun ./src/infra/run.py -h for more options.
Note: email sending relies on Amazon SES (Simple Email Service). So, to send emails, it is required that awscli is installed and credentials are setup. See https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html
From project root, run:
./src/infra/deploy.py [-pip] # by default we don't reinstall pipFrom project root, run:
./src/infra/test.py [path.to.specific.test]