Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Send beeminder word count delta, not cumulative
import re
import requests
import shlex
import subprocess
# login to beeminder and visit
auth_token = 'token'
username = 'username'
goal = 'thesis'
include = re.compile(r"(figures/|tables/|chapters/)?[^/]*.tex$")
url = '{}/goals/{}/datapoints.json'.format(username, goal)
def count(commit):
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))
return words
previous = subprocess.check_output(shlex.split('git log HEAD~2..HEAD~1 --format="%H"')).strip().decode('UTF-8')
current = subprocess.check_output(shlex.split('git log HEAD~1..HEAD~0 --format="%H"')).strip().decode('UTF-8')
comment = subprocess.check_output(shlex.split("git log -1 --format=%B")).strip().decode('UTF-8')
delta = count(current) - count(previous)
if delta > 0:
payload = {
"value": delta,
"comment": comment,
"requestid": commit,
"auth_token": auth_token
r =, data=payload)
print('updated beeminder with {} words'.format(delta))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.