]> projects.mako.cc - iron-blogger/blobdiff - weekly-update.py
fix for a mistake in the punting code
[iron-blogger] / weekly-update.py
index faa6c4cc42dd53f478398c2a126d7f09fc75957d..9cd240c0f53b7b6322f6ccaeef7cb478a66c628d 100755 (executable)
@@ -4,34 +4,87 @@ import os
 import sys
 import xmlrpclib
 import subprocess
+import datetime
+import yaml
 
-XMLRPC_ENDPOINT = 'http://iron-blogger.mit.edu/xmlrpc.php'
-USER            = 'nelhage'
-BLOG_ID         = 1
+from config import *
 
-try:
-    subprocess.call(['stty', '-echo'])
-    passwd = raw_input("Password for %s: " % (USER,))
-    print
-finally:
-    subprocess.call(['stty', 'echo'])
+dry_run = False
 
-x = xmlrpclib.ServerProxy(XMLRPC_ENDPOINT)
+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(render.render_template('templates/ledger', sys.argv[1]))
+    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)
 
-text = render.render_template('templates/week.tmpl', sys.argv[1])
+email = render.render_template('templates/email.txt', date, punt=punt)
 
-lines = text.split("\n")
-title = lines[0]
-body  = "\n".join(lines[1:])
+if dry_run:
+    print email
+else:
+    p = subprocess.Popen(['mutt', '-H', '/dev/stdin'],
+                         stdin=subprocess.PIPE)
+    p.communicate(email)
 
-page = dict(title = title,
-            description = body)
+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'] = datetime.date(*map(int, date.split("-")))
+    with open('bloggers.yml','w') as b:
+        yaml.safe_dump(bloggers, b)
 
-x.metaWeblog.newPost(BLOG_ID, USER, passwd, page, True)
+    if not dry_run:
+        subprocess.check_call(["git", "commit", "ledger", "bloggers.yml",
+                               "-m", "Punts for %s" % (date,)])
 
-p = subprocess.Popen(['mutt', '-H', '/dev/stdin'],
-                     stdin=subprocess.PIPE)
-p.communicate(render.render_template('templates/email.txt', sys.argv[1]))
+# 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"])

Benjamin Mako Hill || Want to submit a patch?