<commit_before>#!/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

try:
    subprocess.call(['stty', '-echo'])
    passwd = raw_input("Password for %s: " % (USER,))
    print
finally:
    subprocess.call(['stty', 'echo'])

x = xmlrpclib.ServerProxy(XMLRPC_ENDPOINT)

with open('ledger', 'a') as f:
    f.write("\n")
    f.write(render.render_template('templates/ledger', sys.argv[1]))

subprocess.check_call(["git", "commit", "ledger",
                       "-m", "Update for %s" % (sys.argv[1],)])

text = render.render_template('templates/week.tmpl', sys.argv[1])

lines = text.split("\n")
title = lines[0]
body  = "\n".join(lines[1:])

page = dict(title = title,
            description = body)

x.metaWeblog.newPost(BLOG_ID, USER, passwd, page, True)

p = subprocess.Popen(['mutt', '-H', '/dev/stdin'],
                     stdin=subprocess.PIPE)
p.communicate(render.render_template('templates/email.txt', sys.argv[1]))<commit_msg>weekly-update: Add -n for dry run.<commit_after>#!/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

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'])

with open('ledger', 'a') as f:
    f.write("\n")
    f.write(render.render_template('templates/ledger', date))

subprocess.check_call(["git", "commit", "ledger",
                       "-m", "Update for %s" % (date,)])

text = render.render_template('templates/week.tmpl', date)

lines = text.split("\n")
title = lines[0]
body  = "\n".join(lines[1:])

page = dict(title = title,
            description = body)

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)

if dry_run:
    print email
else:
    p = subprocess.Popen(['mutt', '-H', '/dev/stdin'],
                         stdin=subprocess.PIPE)
    p.communicate(email)
{'fraction_non_alphanumeric': 0.1750106974753958, 'fraction_numerical': 0.00599058622165169, 'mean_word_length': 3.250909090909091, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1307010', 'n_tokens_mistral': 855, 'n_tokens_neox': 841, 'n_words': 171}