#!/usr/bin/env python """ Wiki Blog Index Author: Sean B. Palmer, inamidst.com """ import cgitb; cgitb.enable() import sys, os, re, glob, time import xml.dom.minidom from pwkblog import first, the r_title = re.compile(r'(?i)([^<]+)') bufsize = 2048 def formatTitle(title): i = title.rfind(' - ') if i > -1: return title[:i] return title def formatDate(date): date, t = tuple(date.rstrip('Z').split('T', 1)) hours, minutes, seconds = tuple(t.split(':', 2)) return date, ':'.join([hours, minutes]) def getText(parent, tag): node = the(parent.getElementsByTagName(tag)) return node.firstChild.toxml() def getinfo(fn): dom = xml.dom.minidom.parse(fn) rdf = the(dom.getElementsByTagName('rdf:RDF')) channel = the(dom.getElementsByTagName('channel')) channelTitle = getText(channel, 'title') channelDescription = getText(channel, 'description') channelItems = [] for itemElement in rdf.getElementsByTagName('item'): item = [] item.append(getText(itemElement, 'title')) item.append(getText(itemElement, 'description')) item.append(getText(itemElement, 'link')) item.append(getText(itemElement, 'dc:date')) channelItems.append(tuple(item)) return channelTitle, channelDescription, channelItems def getTitle(fn): # From http://inamidst.com/inside/notes/updates if not fn.endswith('.html'): return None try: f = open(fn) except: return None else: html = '' while True: s = f.read(bufsize) if not s: break html += s m = r_title.search(html) if m: f.close() return m.group(1) f.close() return None def main(): sys.stdout.write('Content-Type: text/html; charset=utf-8\r\n') sys.stdout.write('\r\n') channelTitle, channelDescription, channelItems = getinfo('rss1.0.rss') print '' print '' print '%s' % channelTitle print '' print '' print '' # print '

%s

' % channelTitle print '

{ inamidst.com, eph }

' print '
' print '

=> ' print '%s ' % channelDescription print '(about)

' if channelItems: print '

Blogworthy Updates

' print "

The following items are from eph's RSS Feed:

' print '' i = 50 # Number of results to show result = {} for fn in glob.glob('*.html'): t = os.stat(fn).st_mtime lastmod = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(t)) while result.has_key(lastmod): lastmod += '_' result[lastmod] = fn[:-len('.html')] keys = result.keys() keys.sort() keys.reverse() keys = keys[:i] print '

All Recent Changes

' print '

The %s most recent changes in this site are:

' % len(keys) print '
' for n in keys: pdate, ptime = tuple(n.split(' ')) ptime = ptime.rstrip('_') print '
%s: ' % pdate, title = result[n] htitle = getTitle(result[n] + '.html') if htitle and (htitle != title): title = htitle title = formatTitle(title) print '%s %s' % (result[n], title, ptime), length = len(open(result[n] + '.html').read()) print ' (size: %s bytes)
' % length print '
' print '

Up to %s updates will be shown.

' % i print '

About Eph

' print '

For more information about the site in general, try about. Also: this ' print "page's source.

" print '
' print '
' print 'Sean B. Palmer' print '
' print '' print '' if __name__=="__main__": main()