Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ Tells when datapoint has been created.
`<day>` should be the day of the month or `^` for today. Multiple `^` (e.g.
`^^` for yesterday) are not supported.

### Configuration File
The username and API key to be used for the transaction
should be stored in a configuration file, `~/.beeminder` by default.
The format should be a shell script which puts the credentials in the variables
`key`, and `user`.
e.g.
```
# ~/.beeminder
------
user='some_user_name'
key='Jqt6szDj5WJfm2YyBANU'
```

### Viewing goal status
```
> bee <goal>
Expand All @@ -21,9 +34,10 @@ Exit status | Meaning
----------: | :---------
0 | Everything went properly
1 | Goal not found
2 | Invalid day argument
3 | Datum is not a number
4 | Wrong number of arguments
2 | Configuration file not found
3 | Invalid day argument
4 | Datum is not a number
5 | Wrong number of arguments

Errors are checked in descending order, so if multiple errors exist, the largest
exit status takes precedence.
Expand Down
20 changes: 15 additions & 5 deletions bee
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#! /bin/bash

base='https://www.beeminder.com/api/v1/'
# user=''
# key=''

goal=$1
date=$2
Expand All @@ -14,7 +12,7 @@ function check_data() {
if [[ ! $data =~ ^-?[0-9]+(\.[0-9]+)?$ ]]
then
echo "data must be a number" >&2
exit 3
exit 4
fi
}

Expand All @@ -39,7 +37,7 @@ else
if [[ $? != 0 ]]
then
# invalid date
exit 2
exit 3
fi
fi
}
Expand Down Expand Up @@ -69,23 +67,35 @@ function goal_status() {
curl -s "${base}users/${user}/goals/${goal}.json?auth_token=${key}" |sed 's/^.*\"headsum\":\"\([^"]*\)\".*$/\1\n/'
}

function get_credentials() {
if [[ -e ~/.beeminder ]]
then
. ~/.beeminder
else
echo "Credential file ~/.beeminder not found" >&2
exit 2
fi
}

case $# in
3|4 )
# submit data point
check_data
process_date
get_credentials
check_goal
submit
exit 0
;;
1 )
# get goal status
get_credentials
check_goal
goal_status
;;
* )
# wrong number of arguments
echo "Usage: $(basename $0) <goal> <day> <datum> [comment]" >&2
exit 4
exit 5
;;
esac