Skip to content

Instantly share code, notes, and snippets.

@annawoodard
Last active May 28, 2017 13:56
Show Gist options
  • Save annawoodard/94e8e1a23fe14675b7db64a5435f8916 to your computer and use it in GitHub Desktop.
Save annawoodard/94e8e1a23fe14675b7db64a5435f8916 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/python3
import requests
import shlex
import subprocess
# login to beeminder and visit https://www.beeminder.com/api/v1/auth_token.json
auth_token = 'token'
username = 'username'
goal = 'thesis'
url = 'https://www.beeminder.com/api/v1/users/{}/goals/{}/datapoints.json'.format(username, goal)
commit = subprocess.check_output(shlex.split('git log -1 --format="%H"')).strip().decode('UTF-8')
cmd = "git show --numstat {} | grep tex | awk '{{sum+=$1+$2}} END {{print sum;}}'"
lines = int(subprocess.check_output(cmd.format(commit), shell=True))
comment = subprocess.check_output(shlex.split("git log -1 --format=%B")).strip().decode('UTF-8')
if lines > 0:
payload = {
"value": lines,
"comment": comment,
"requestid": commit,
"auth_token": auth_token
}
r = requests.post(url, data=payload)
print('updated beeminder with {} changed lines'.format(lines))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment