Do the ledger and email in weekly-update.
[iron-blogger] / weekly-update.py
1 #!/usr/bin/python
2 import render
3 import os
4 import sys
5 import xmlrpclib
6 import subprocess
7
8 XMLRPC_ENDPOINT = 'http://iron-blogger.mit.edu/xmlrpc.php'
9 USER            = 'nelhage'
10 BLOG_ID         = 1
11
12 try:
13     subprocess.call(['stty', '-echo'])
14     passwd = raw_input("Password for %s: " % (USER,))
15     print
16 finally:
17     subprocess.call(['stty', 'echo'])
18
19 x = xmlrpclib.ServerProxy(XMLRPC_ENDPOINT)
20
21 with open('ledger', 'a') as f:
22     f.write(render.render_template('templates/ledger', sys.argv[1]))
23
24 text = render.render_template('templates/week.tmpl', sys.argv[1])
25
26 lines = text.split("\n")
27 title = lines[0]
28 body  = "\n".join(lines[1:])
29
30 page = dict(title = title,
31             description = body)
32
33 x.metaWeblog.newPost(BLOG_ID, USER, passwd, page, True)
34
35 p = subprocess.Popen(['mutt', '-H', '/dev/stdin'],
36                      stdin=subprocess.PIPE)
37 p.communicate(render.render_template('templates/email.txt', sys.argv[1]))

Benjamin Mako Hill || Want to submit a patch?