AUTOPUNT
This commit is contained in:
parent
81be85441f
commit
d9449b6b58
|
@ -33,7 +33,7 @@ def get_debts():
|
||||||
debts.append((user, val))
|
debts.append((user, val))
|
||||||
return debts
|
return debts
|
||||||
|
|
||||||
def render_template(path, week=None):
|
def render_template(path, week=None, **kwargs):
|
||||||
with open('out/report.yml') as r:
|
with open('out/report.yml') as r:
|
||||||
report = yaml.safe_load(r)
|
report = yaml.safe_load(r)
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ def render_template(path, week=None):
|
||||||
week=week, week_start=week_start,week_end=week_end,
|
week=week, week_start=week_start,week_end=week_end,
|
||||||
good=good, lame=lame, skip=skip, userlist=userlist,
|
good=good, lame=lame, skip=skip, userlist=userlist,
|
||||||
pool=get_balance('Pool'), paid=get_balance('Pool:Paid'),
|
pool=get_balance('Pool'), paid=get_balance('Pool:Paid'),
|
||||||
debts=debts)
|
debts=debts, **kwargs)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
|
|
|
@ -2,6 +2,7 @@ Subject: IRON BLOGGER results for the week beginning ${week_start.strftime("%F")
|
||||||
To: iron-blogger@mit.edu
|
To: iron-blogger@mit.edu
|
||||||
|
|
||||||
SLACKERS: ${", ".join(sorted([u.username for u in lame]))}
|
SLACKERS: ${", ".join(sorted([u.username for u in lame]))}
|
||||||
|
PUNTED for balance greater than $30: ${", ".join(sorted(punt))}
|
||||||
|
|
||||||
People who posted:
|
People who posted:
|
||||||
% for u in sorted(good, key=lambda u:u.username):
|
% for u in sorted(good, key=lambda u:u.username):
|
||||||
|
|
|
@ -20,6 +20,15 @@ Results for week beginning ${week_start.strftime("%F")}
|
||||||
% endfor
|
% endfor
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
% if punt:
|
||||||
|
<h2>People punted for excessive outstanding balances:</h2>
|
||||||
|
<ul>
|
||||||
|
% for u in sorted(punt):
|
||||||
|
<li class="user">${u}</li>
|
||||||
|
% endfor
|
||||||
|
</ul>
|
||||||
|
% endif
|
||||||
|
|
||||||
% if skip:
|
% if skip:
|
||||||
<h2>People who have not yet started</h2>
|
<h2>People who have not yet started</h2>
|
||||||
<ul>
|
<ul>
|
||||||
|
|
|
@ -4,24 +4,22 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import xmlrpclib
|
import xmlrpclib
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import datetime
|
||||||
|
import yaml
|
||||||
|
|
||||||
XMLRPC_ENDPOINT = 'http://iron-blogger.mit.edu/xmlrpc.php'
|
XMLRPC_ENDPOINT = 'http://iron-blogger.mit.edu/xmlrpc.php'
|
||||||
USER = 'nelhage'
|
USER = 'nelhage'
|
||||||
BLOG_ID = 1
|
BLOG_ID = 1
|
||||||
|
|
||||||
|
dry_run = False
|
||||||
|
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
if args[0] == '-n':
|
if args[0] == '-n':
|
||||||
dry_run = True
|
dry_run = True
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
|
|
||||||
date = args[0]
|
date = args[0]
|
||||||
|
today = str(datetime.date.today())
|
||||||
try:
|
|
||||||
subprocess.call(['stty', '-echo'])
|
|
||||||
passwd = raw_input("Password for %s: " % (USER,))
|
|
||||||
print
|
|
||||||
finally:
|
|
||||||
subprocess.call(['stty', 'echo'])
|
|
||||||
|
|
||||||
with open('ledger', 'a') as f:
|
with open('ledger', 'a') as f:
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
|
@ -30,20 +28,41 @@ with open('ledger', 'a') as f:
|
||||||
subprocess.check_call(["git", "commit", "ledger",
|
subprocess.check_call(["git", "commit", "ledger",
|
||||||
"-m", "Update for %s" % (date,)])
|
"-m", "Update for %s" % (date,)])
|
||||||
|
|
||||||
text = render.render_template('templates/week.tmpl', date)
|
debts = render.get_debts()
|
||||||
|
punt = []
|
||||||
|
|
||||||
|
with open('ledger', 'a') as f:
|
||||||
|
f.write("\n")
|
||||||
|
for (user, debt) in debts:
|
||||||
|
if debt < 30: continue
|
||||||
|
punt.append(user)
|
||||||
|
f.write("""\
|
||||||
|
%(today)s Punt
|
||||||
|
Pool:Owed:%(user)s $-%(debt)s
|
||||||
|
User:%(user)s
|
||||||
|
""" % {'user': user, 'debt': debt, 'today': today})
|
||||||
|
|
||||||
|
|
||||||
|
if not dry_run:
|
||||||
|
text = render.render_template('templates/week.tmpl', date, punt=punt)
|
||||||
|
|
||||||
lines = text.split("\n")
|
lines = text.split("\n")
|
||||||
title = lines[0]
|
title = lines[0]
|
||||||
body = "\n".join(lines[1:])
|
body = "\n".join(lines[1:])
|
||||||
|
|
||||||
page = dict(title = title,
|
page = dict(title = title, description = body)
|
||||||
description = body)
|
|
||||||
|
try:
|
||||||
|
subprocess.call(['stty', '-echo'])
|
||||||
|
passwd = raw_input("Password for %s: " % (USER,))
|
||||||
|
print
|
||||||
|
finally:
|
||||||
|
subprocess.call(['stty', 'echo'])
|
||||||
|
|
||||||
if not dry_run:
|
|
||||||
x = xmlrpclib.ServerProxy(XMLRPC_ENDPOINT)
|
x = xmlrpclib.ServerProxy(XMLRPC_ENDPOINT)
|
||||||
x.metaWeblog.newPost(BLOG_ID, USER, passwd, page, True)
|
x.metaWeblog.newPost(BLOG_ID, USER, passwd, page, True)
|
||||||
|
|
||||||
email = render.render_template('templates/email.txt', date)
|
email = render.render_template('templates/email.txt', date, punt=punt)
|
||||||
|
|
||||||
if dry_run:
|
if dry_run:
|
||||||
print email
|
print email
|
||||||
|
@ -51,3 +70,15 @@ else:
|
||||||
p = subprocess.Popen(['mutt', '-H', '/dev/stdin'],
|
p = subprocess.Popen(['mutt', '-H', '/dev/stdin'],
|
||||||
stdin=subprocess.PIPE)
|
stdin=subprocess.PIPE)
|
||||||
p.communicate(email)
|
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'] = today
|
||||||
|
with open('bloggers.yml','w') as b:
|
||||||
|
yaml.safe_dump(bloggers, b)
|
||||||
|
|
||||||
|
subprocess.check_call(["git", "commit", "ledger", "bloggers.yml",
|
||||||
|
"-m", "Punts for %s" % (today,)])
|
||||||
|
|
Loading…
Reference in New Issue