You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.8 KiB

# This Python file uses the following encoding: utf-8
import render
import os
import sys
import xmlrpc.client
import subprocess
13 years ago
import datetime
import yaml
import settings
13 years ago
dry_run = False
send_mail = True
quick_view = False
reminder = False
13 years ago
args = sys.argv[1:]
if len(args)>0:
if args[0] == '-q':
dry_run = True
quick_view = True
send_mail = False
args = args[1:]
if args[0] == '-r':
dry_run = True
reminder = True
args = args[1:]
if args[0] == '-n':
dry_run = True
send_mail = False
args = args[1:]
date = args[0]
with open('ledger', 'a') as f:
# print(render.render_template('templates/ledger', date).decode("utf-8"))
f.write(render.render_template('templates/ledger', date).decode("utf-8"))
if not dry_run:
subprocess.check_call(["git", "commit", "ledger",
"-m", "Update for %s" % (date,)])
13 years ago
debts = render.get_debts()
punt = []
13 years ago
with open('ledger', 'a') as f:
for (user, debt) in debts:
if debt < 30: continue
%(date)s Punt
13 years ago
Pool:Owed:%(user)s $-%(debt)s
""" % {'user': user, 'debt': debt, 'date': date})
if not dry_run:
text = render.render_template('templates/week.tmpl', date, punt=punt).decode("utf-8")
13 years ago
lines = text.split("\n")
title = lines[0]
body = "\n".join(lines[1:])
page = dict(title = title, description = body)
x = xmlrpc.client.ServerProxy(config['xmlrpc_endpoint'])
11 years ago
x.metaWeblog.newPost(config['blog_id'], config['username'], config['password'], page, True)
if not reminder:
email = render.render_template('templates/email.txt', date, punt=punt,mail=config['mail'])
email = render.render_template('templates/reminder.txt', date, punt=punt,mail=config['mail'])
if quick_view:
if dry_run and not quick_view:
if send_mail:
# p = subprocess.Popen(['mutt', '-H', '/dev/stdin'],
p = subprocess.Popen(['/usr/sbin/sendmail', '-oi', '-t'],
13 years ago
if punt and not dry_run:
13 years ago
with open('bloggers.yml') as b:
bloggers = yaml.safe_load(b)
for p in punt:
if 'end' not in bloggers[p]:
bloggers[p]['end'] = date
13 years ago
with open('bloggers.yml','w') as b:
yaml.safe_dump(bloggers, b)
subprocess.check_call(["git", "commit", "ledger", "bloggers.yml",
"-m", "Punts for %s" % (date,)])
# if it's a dry run, lets set the ledger back to the beginning state
if dry_run:
subprocess.check_call(["git", "checkout", "ledger"])