]> projects.mako.cc - iron-blogger/blobdiff - weekly-update.py
I forgot to add payments given to me at the CBC meetup.
[iron-blogger] / weekly-update.py
index b87e37ef7e4453b04a8fc3cbc8c646b686c24802..4aa749c6156cf0d2cfae51df841b337028bb54d1 100755 (executable)
@@ -4,24 +4,22 @@ 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
 
+dry_run = False
+
 args = sys.argv[1:]
 if args[0] == '-n':
     dry_run = True
     args = args[1:]
 
 date = args[0]
-
-try:
-    subprocess.call(['stty', '-echo'])
-    passwd = raw_input("Password for %s: " % (USER,))
-    print
-finally:
-    subprocess.call(['stty', 'echo'])
+today = str(datetime.date.today())
 
 with open('ledger', 'a') as f:
     f.write("\n")
@@ -30,20 +28,41 @@ with open('ledger', 'a') as f:
 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("""\
+%(today)s Punt
+  Pool:Owed:%(user)s  $-%(debt)s
+  User:%(user)s
+""" % {'user': user, 'debt': debt, 'today': today})
 
-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,15 @@ 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'] = 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,)])

Benjamin Mako Hill || Want to submit a patch?