forked from nelhage/iron-blogger
-
Notifications
You must be signed in to change notification settings - Fork 1
/
weekly-update.py
executable file
·90 lines (70 loc) · 2.15 KB
/
weekly-update.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python
import render
import os
import sys
import xmlrpclib
import subprocess
import datetime
import yaml
from config import *
dry_run = False
args = sys.argv[1:]
if args[0] == '-n':
dry_run = True
args = args[1:]
date = args[0]
with open('ledger', 'a') as f:
f.write("\n")
f.write(render.render_template('templates/ledger', date))
if not dry_run:
subprocess.check_call(["git", "commit", "ledger",
"-m", "Update for %s" % (date,)])
debts = render.get_debts()
punt = []
with open('ledger', 'a') as f:
f.write("\n")
for (user, debt) in debts:
if debt <= (FINE_SIZE * 6): continue
punt.append(user)
f.write("""\
%(date)s Punt
Pool:Owed:%(user)s -%(debt)s
User:%(user)s
""" % {'user': user, 'debt': debt, 'date': date})
if not dry_run:
text = render.render_template('templates/week.tmpl', date, punt=punt)
lines = text.split("\n")
title = lines[0]
body = "\n".join(lines[1:])
page = dict(title = title, description = body)
try:
subprocess.call(['stty', '-echo'])
passwd = raw_input("Password for %s: " % (USER,))
print
finally:
subprocess.call(['stty', 'echo'])
x = xmlrpclib.ServerProxy(XMLRPC_ENDPOINT)
x.metaWeblog.newPost(BLOG_ID, USER, passwd, page, True)
email = render.render_template('templates/email.txt', date, punt=punt)
if dry_run:
print email
else:
p = subprocess.Popen(['mutt', '-H', '/dev/stdin'],
stdin=subprocess.PIPE)
p.communicate(email)
if punt:
with open('bloggers.yml') as b:
bloggers = yaml.safe_load(b)
for p in punt:
if 'end' not in bloggers[p]:
bloggers[p]['end'] = date
with open('bloggers.yml','w') as b:
yaml.safe_dump(bloggers, b)
if not dry_run:
subprocess.check_call(["git", "commit", "ledger", "bloggers.yml",
"-m", "Punts for %s" % (date,)])
# if it's a dry run, lets set the ledger back to the beginning state
if dry_run:
subprocess.check_call(["git", "checkout", "ledger"])
if punt:
subprocess.check_call(["git", "checkout", "bloggers.yml"])