iron-blogger/weekly-update.py

54 lines
1.2 KiB
Python
Raw Normal View History

2010-02-02 03:07:26 +00:00
#!/usr/bin/python
import render
import os
import sys
import xmlrpclib
import subprocess
XMLRPC_ENDPOINT = 'http://iron-blogger.mit.edu/xmlrpc.php'
USER = 'nelhage'
BLOG_ID = 1
2010-06-01 00:40:47 +00:00
args = sys.argv[1:]
if args[0] == '-n':
dry_run = True
args = args[1:]
date = args[0]
2010-02-02 03:07:26 +00:00
try:
subprocess.call(['stty', '-echo'])
passwd = raw_input("Password for %s: " % (USER,))
print
finally:
subprocess.call(['stty', 'echo'])
with open('ledger', 'a') as f:
f.write("\n")
2010-06-01 00:40:47 +00:00
f.write(render.render_template('templates/ledger', date))
subprocess.check_call(["git", "commit", "ledger",
2010-06-01 00:40:47 +00:00
"-m", "Update for %s" % (date,)])
2010-06-01 00:40:47 +00:00
text = render.render_template('templates/week.tmpl', date)
2010-02-02 03:07:26 +00:00
lines = text.split("\n")
title = lines[0]
body = "\n".join(lines[1:])
page = dict(title = title,
description = body)
2010-06-01 00:40:47 +00:00
if not dry_run:
x = xmlrpclib.ServerProxy(XMLRPC_ENDPOINT)
x.metaWeblog.newPost(BLOG_ID, USER, passwd, page, True)
email = render.render_template('templates/email.txt', date)
2010-06-01 00:40:47 +00:00
if dry_run:
print email
else:
p = subprocess.Popen(['mutt', '-H', '/dev/stdin'],
stdin=subprocess.PIPE)
p.communicate(email)