]> projects.mako.cc - iron-blogger/blob - weekly-update.py
weekly-update: Add -n for dry run.
[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 args = sys.argv[1:]
13 if args[0] == '-n':
14     dry_run = True
15     args = args[1:]
16
17 date = args[0]
18
19 try:
20     subprocess.call(['stty', '-echo'])
21     passwd = raw_input("Password for %s: " % (USER,))
22     print
23 finally:
24     subprocess.call(['stty', 'echo'])
25
26 with open('ledger', 'a') as f:
27     f.write("\n")
28     f.write(render.render_template('templates/ledger', date))
29
30 subprocess.check_call(["git", "commit", "ledger",
31                        "-m", "Update for %s" % (date,)])
32
33 text = render.render_template('templates/week.tmpl', date)
34
35 lines = text.split("\n")
36 title = lines[0]
37 body  = "\n".join(lines[1:])
38
39 page = dict(title = title,
40             description = body)
41
42 if not dry_run:
43     x = xmlrpclib.ServerProxy(XMLRPC_ENDPOINT)
44     x.metaWeblog.newPost(BLOG_ID, USER, passwd, page, True)
45
46 email = render.render_template('templates/email.txt', date)
47
48 if dry_run:
49     print email
50 else:
51     p = subprocess.Popen(['mutt', '-H', '/dev/stdin'],
52                          stdin=subprocess.PIPE)
53     p.communicate(email)

Benjamin Mako Hill || Want to submit a patch?