X-Git-Url: https://projects.mako.cc/source/iron-blogger/blobdiff_plain/5b056df8f265e7f31e5cc46d7101c74304b7fe01..b612fb1d1f032220bb3b9d231bcca06568078adc:/weekly-update.py?ds=inline diff --git a/weekly-update.py b/weekly-update.py index b87e37e..7a44dff 100755 --- a/weekly-update.py +++ b/weekly-update.py @@ -4,11 +4,15 @@ import os import sys import xmlrpclib import subprocess +import datetime +import yaml -XMLRPC_ENDPOINT = 'http://iron-blogger.mit.edu/xmlrpc.php' -USER = 'nelhage' +XMLRPC_ENDPOINT = 'http://iron-blogger.mako.cc/xmlrpc.php' +USER = 'mako' BLOG_ID = 1 +dry_run = False + args = sys.argv[1:] if args[0] == '-n': dry_run = True @@ -16,34 +20,49 @@ if args[0] == '-n': date = args[0] -try: - subprocess.call(['stty', '-echo']) - passwd = raw_input("Password for %s: " % (USER,)) - print -finally: - subprocess.call(['stty', 'echo']) - with open('ledger', 'a') as f: f.write("\n") f.write(render.render_template('templates/ledger', date)) -subprocess.check_call(["git", "commit", "ledger", - "-m", "Update for %s" % (date,)]) +if not dry_run: + subprocess.check_call(["git", "commit", "ledger", + "-m", "Update for %s" % (date,)]) -text = render.render_template('templates/week.tmpl', date) +debts = render.get_debts() +punt = [] -lines = text.split("\n") -title = lines[0] -body = "\n".join(lines[1:]) +with open('ledger', 'a') as f: + f.write("\n") + for (user, debt) in debts: + if debt < 30: continue + punt.append(user) + f.write("""\ +%(date)s Punt + Pool:Owed:%(user)s $-%(debt)s + User:%(user)s +""" % {'user': user, 'debt': debt, 'date': date}) -page = dict(title = title, - description = body) 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) +email = render.render_template('templates/email.txt', date, punt=punt) if dry_run: print email @@ -51,3 +70,23 @@ 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"])