-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost-commit
More file actions
executable file
·40 lines (31 loc) · 1.44 KB
/
post-commit
File metadata and controls
executable file
·40 lines (31 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/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 = 'FIXME'
user = 'annawoodard'
goal = 'thesis'
include = re.compile(r"(figures/|tables/|chapters/)?[^/]*.tex$")
url = 'https://www.beeminder.com/api/v1/users/{user}/goals/{goal}.json'.format(user=user, goal=goal)
data = requests.get(url, data={"auth_token": auth_token, "skinny": True}).json()
previous = int(float(data['baremintotal'])) - int(float(data['baremin']))
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
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) - previous
url = 'https://www.beeminder.com/api/v1/users/{}/goals/{}/datapoints.json'.format(user, goal)
payload = {
"value": delta,
"comment": comment,
"requestid": current,
"auth_token": auth_token
}
r = requests.post(url, data=payload)
print('updated beeminder with {} words'.format(delta))