Skip to content

Instantly share code, notes, and snippets.

@nakomis
Last active August 29, 2015 14:17
Show Gist options
  • Save nakomis/64be315e54b0316b7325 to your computer and use it in GitHub Desktop.
Save nakomis/64be315e54b0316b7325 to your computer and use it in GitHub Desktop.
Harvesting harvest
#!/bin/bash
# Usage: harvest [d [m [yyyy]]]
# Assumes the presence of harvest.env in the subfolder 'ignored' of the folder in which this script is located
# The contents of the file should be as follow:
# export USER_NAME=martin.harris@cloudsoftcorp.com
# export PASSWORD=hunter2
. $(dirname $0)/ignored/harvest.env
if [ -n "$3" ]; then
year=$3
else
year=$(date +%Y)
fi
if [ -n "$2" ]; then
month=$2
else
month=$(date +%m)
fi
if [ -n "$1" ]; then
day=$(date -f "%Y-%m-%d" -j "$year-$month-$1" +"%j")
else
day=$(date +%j)
fi
raw=`curl -H 'Content-Type: application/xml' -H 'Accept: application/xml' \
-u $USER_NAME:$PASSWORD https://cloudsoft.harvestapp.com/daily/$day/$year \
| xpath '//daily//day_entries//day_entry//notes \
| //daily//day_entries//day_entry//task \
| //daily//day_entries//day_entry//project'`
trimmed=${raw//<\/notes>/\\n}
trimmed=${trimmed//<project>/}
trimmed=${trimmed//<\/project><task>/: }
trimmed=${trimmed//<\/task><notes>/: }
trimmed=${trimmed//&amp;/&}
trimmed=${trimmed//&amp;/&}
echo -e $trimmed | pbcopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment