]> projects.mako.cc - iron-blogger/commitdiff
Include more monetary information in reports.
authorNelson Elhage <nelhage@ksplice.com>
Mon, 24 May 2010 00:33:53 +0000 (20:33 -0400)
committerNelson Elhage <nelhage@ksplice.com>
Mon, 24 May 2010 00:33:53 +0000 (20:33 -0400)
render.py
templates/email.txt
templates/week.tmpl

index 8cda0d52b3808d8bead38e3229242d17b9ca3632..0a7bf46f488d68095a370ac722467aa8631d2c82 100755 (executable)
--- a/render.py
+++ b/render.py
@@ -66,16 +66,30 @@ def render_template(path, week=None):
         else:
             good.append(u)
 
+    def get_balance(acct):
+        p = subprocess.Popen(['ledger', '-f', os.path.join(HERE,'ledger'),
+                              '-n', 'balance', acct],
+                             stdout=subprocess.PIPE)
+        (out, _) = p.communicate()
+        return int(out.split()[0][1:])
+
     p = subprocess.Popen(['ledger', '-f', os.path.join(HERE,'ledger'),
-                          '-n', 'balance', 'Pool'],
+                          '-n', 'balance', 'Pool:Owed:'],
                          stdout=subprocess.PIPE)
     (out, _) = p.communicate()
-    pool = int(out.split()[0][1:])
+    debts = []
+    for line in out.split("\n"):
+        if not line: continue
+        (val, acct) = line.split()
+        user = acct[len("Pool:Owed:"):]
+        val  = int(val[len("$"):])
+        debts.append((user, val))
 
     return Template(filename=path, output_encoding='utf-8').render(
         week=week, week_start=week_start,week_end=week_end,
         good=good, lame=lame, skip=skip, userlist=userlist,
-        pool=pool)
+        pool=get_balance('Pool'), paid=get_balance('Pool:Paid'),
+        debts=debts)
 
 if __name__ == '__main__':
     if len(sys.argv) < 2:
index aab3428bb769a9254a0c042ee4f4e142c3a3d4bf..e82b15fb59e1add6f3110110f7402be769266d85 100644 (file)
@@ -21,3 +21,9 @@ People who have not yet started:
 Beer pool:
 This week: $${5 * len(lame)}.00
 Total:     $${pool}.00
+Paid:      $${paid}.00
+
+Individual debts:
+% for (u, v) in sorted(debts, key=lambda p:p[1], reverse=True):
+${"%20s $%d" % (u, v)}
+% endfor
index 68f6474dc3c00469ed99bee8d516e941aba79683..4ed842fcbb886233507de7c17bf315dc07e84ea0 100644 (file)
@@ -31,5 +31,13 @@ Results for week beginning ${week_start.strftime("%F")}
 <h2>Beer pool:</h2>
 <table>
   <tr> <td> This week: </td> <td> $${5 * len(lame)}.00 </td> </tr>
-  <tr> <td> Total: </td> <td> ${pool}.00 </td> </tr>
+  <tr> <td> Total: </td> <td> $${pool}.00 </td> </tr>
+  <tr> <td> Paid: </td> <td> $${paid}.00 </td> </tr>
+</table>
+
+<h2>Debts:</h2>
+<table>
+% for (u, v) in sorted(debts, key=lambda p:p[1], reverse=True):
+<tr><td>${u}</td> <td>${v}</td></tr>
+% endfor
 </table>

Benjamin Mako Hill || Want to submit a patch?