Skip to content

Instantly share code, notes, and snippets.

@matz-e
Forked from annawoodard/beeminder.py
Last active May 29, 2017 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save matz-e/7abcbf6f13b31934d24091353bcb9bb1 to your computer and use it in GitHub Desktop.
Save matz-e/7abcbf6f13b31934d24091353bcb9bb1 to your computer and use it in GitHub Desktop.
Update beeminder with TeX wordcount
#!/usr/local/bin/python3
import re
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'
include = re.compile(r"(figures/|tables/|chapters/)?[^/]*.tex$")
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')
files = subprocess.check_output(["git", "ls-tree", "-r", "--name-only", commit]).decode('UTF-8').split()
files = [fn for fn in files if include.match(fn)]
cmd = "git show {}|texcount -|awk '/Words in text:/ {{print $4}}'".format(" ".join(commit + ":" + fn for fn in files))
words = int(subprocess.check_output(cmd, shell=True))
comment = subprocess.check_output(shlex.split("git log -1 --format=%B")).strip().decode('UTF-8')
if words > 0:
payload = {
"value": words,
"comment": comment,
"requestid": commit,
"auth_token": auth_token
}
r = requests.post(url, data=payload)
print('updated beeminder with {} words'.format(words))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment