Daily Email Report of Time Entries using the Harvest API and Mailgun API
v1.0.0 was originally discussed in our workshop blog post here: Daily Harvest. Since writing that blog post, iron.io has come out with their dockerized worker which we have adopted in this version 2.0. You can now use this project as either:
- python script
- docker app
- iron.io worker
There are 2 components to daily-harvest. You can choose to use one or both (they are not interdepentant)
Sends an email out to a list of receiptients with detailed timesheets as well as total hours by employee and project.
Replicates the past 24 hours of punches inside a MySQL database table called "timesheet"
The following services are required:
- mailgun account
- email list
- harvest account
- harvest account
- mysql database - you must install
harvest_backup.sql
on a mysql database and make it accessable to the backup app.
This has been tested on python 2.7
-
Install the requirements. If you have any issues, be sure to have already installed python development libraries for your OS (i.e. python-dev or python-devel).
pip install -t packages -r requirements.txt
-
The script reads environment variables rather than passing parameters (this is to keep compliant with docker/iron.io). Set environment variables as you normally work for you operating system and be sure python has access to them. The following environment variables are required:
# HARVEST CREDENCIALS HARVEST_URI HARVEST_EMAIL HARVEST_PASSWORD # daily-harvest:email # MAILGUN SETTINGS MAILGUN_KEY= MAILGUN_DOMAIN= MAILGUN_FROM= # COMMA SEPARATED LIST OF EMAIL ADDRESSES (NO SPACES) RECIPIENTS= # daily-harvest:backup # MYSQL SETTINGS MYSQL_USER= MYSQL_PASSWORD= MYSQL_DATABASE= MYSQL_HOST= MYSQL_PORT=
-
Run the script
# Email python harvest_email.py # Backup python harvest_backup.py
-
pull the image
# Pull the email version docker pull docker.io/avatarnewyork/daily-harvest:email # Pull the backup version docker pull docker.io/avatarnewyork/daily-harvest:backup
-
Execute and pass appropriate environment variables
# Email docker run --rm -e 'HARVEST_URI=https://myco.harvestapp.com' -e '[email protected]' -e 'HARVEST_PASSWORD=secret' -e 'MAILGUN_DOMAIN=mg.mydomain.com' -e 'MAILGUN_KEY=key-asdfkljasdf' -e '[email protected]' -e '[email protected]' daily-harvest:email # Backup docker run --rm -e 'HARVEST_URI=https://myco.harvestapp.com' -e '[email protected]' -e 'HARVEST_PASSWORD=secret' -e 'MYSQL_USER=harvest' -e 'MYSQL_PASSWORD=secretpwd' -e 'MYSQL_DATABASE=harvest' -e 'MYSQL_HOST=72.43.52.10' -e 'MYSQL_PORT=3306' daily-harvest:email
-
Setup your credencials / projectid, etc. See: http://dev.iron.io/worker/getting_started/
-
Register email
iron register -e 'HARVEST_URI=https://myco.harvestapp.com' -e '[email protected]' -e 'HARVEST_PASSWORD=secret' -e 'MAILGUN_DOMAIN=mg.mydomain.com' -e 'MAILGUN_KEY=key-asdfkljasdf' -e '[email protected]' -e '[email protected]' daily-harvest:backup
-
Register backup
iron register -e 'HARVEST_URI=https://myco.harvestapp.com' -e '[email protected]' -e 'HARVEST_PASSWORD=secret' -e 'MYSQL_USER=harvest' -e 'MYSQL_PASSWORD=secretpwd' -e 'MYSQL_DATABASE=harvest' -e 'MYSQL_HOST=72.43.52.10' -e 'MYSQL_PORT=3306' daily-harvest:baclkup
-
queue / schedule on iron.io. See: http://dev.iron.io/worker/getting_started/
For information regarding the v1.0 version, checkout the v1.0.0 branch or tag.