python-peps /

The default branch has multiple heads

#!/usr/bin/env python

# usage: $REPOS $REV
# (standard post-commit args)

import os, glob, time, datetime, stat, re, sys
import codecs
import PyRSS2Gen as rssgen

RSS_PATH = os.path.join(sys.argv[1], 'peps.rss')

def firstline_startingwith(full_path, text):
    for line in, encoding="utf-8"):
        if line.startswith(text):
            return line[len(text):].strip()
    return None

# get list of peps with creation time (from "Created:" string in pep .txt)
peps = glob.glob('pep-*.txt')
def pep_creation_dt(full_path):
    created_str = firstline_startingwith(full_path, 'Created:')
    # bleh, I was hoping to avoid re but some PEPs editorialize
    # on the Created line
    m ='''(\d+-\w+-\d{4})''', created_str)
    if not m:
        # some older ones have an empty line, that's okay, if it's old
        # we ipso facto don't care about it.
        # "return None" would make the most sense but datetime objects
        # refuse to compare with that. :-|
        return datetime.datetime(*time.localtime(0)[:6])
    created_str =
        t = time.strptime(created_str, '%d-%b-%Y')
    except ValueError:
        t = time.strptime(created_str, '%d-%B-%Y')
    return datetime.datetime(*t[:6])
peps_with_dt = [(pep_creation_dt(full_path), full_path) for full_path in peps]
# sort peps by date, newest first

# generate rss items for 10 most recent peps
items = []
for dt, full_path in peps_with_dt[:10]:
        n = int(full_path.split('-')[-1].split('.')[0])
    except ValueError:
    title = firstline_startingwith(full_path, 'Title:')
    author = firstline_startingwith(full_path, 'Author:')
    url = '' % n
    item = rssgen.RSSItem(
        title = 'PEP %d: %s' % (n, title),
        link = url,
        description = 'Author: %s' % author,
        guid = rssgen.Guid(url),
        pubDate = dt)

# the rss envelope
desc = """
Newest Python Enhancement Proposals (PEPs) - Information on new
language features, and some meta-information like release
procedure and schedules
rss = rssgen.RSS2(
    title = 'Newest Python PEPs',
    link = '',
    description = desc,
    lastBuildDate =,
    items = items)

file(RSS_PATH, 'w').write(rss.to_xml())