#!/usr/bin/python import sys import re chunks = [] for l in sys.stdin.readlines(): l2 = l.strip().replace(r'\n',' ') chunks.append(dict(zip(["mysqlid","type","entry","content","stamp","owner"], l2.split('\t')))) # Hack to unpack old perl freezethaw stuff if chunks[-1]['content'].startswith('FRZ'): c = chunks[-1]['content'] _,_,_,data = c.split('|',3) d = [ x.split('$')[0] for x in data.split('|')] d[-1] = d[-1].rstrip('}') d2 = dict(zip(d[0:3],d[3:6])) chunks[-1]['content'] = d2 #print chunks[-1]['type'] entries = dict([(x['entry'],1) for x in chunks]).keys() def sub_help(m,which,content): if m.group(1) in content: if isinstance(content[m.group(1)],dict): return template('%s_content'%which,content[m.group(1)]) else: return content[m.group(1)] else: return ''%m.group(1) templates = {} tre = re.compile('%\((.*?)\)') def template(which, content): print which + ' : '+ str(content)[:15] if not which in templates: try: templates[which] = open('hs/templates/%s.html'%which).read() except: templates[which] = open('hs/templates/default.html').read() t = templates[which] return tre.sub(lambda m: sub_help(m,which,content),t) n = open('public_html/hs/hs-list.html','w') hsdate_sort = lambda x,y: cmp(x[-2:]+x[:-2], y[-2:]+y[:-2]) for e in sorted(entries,hsdate_sort): e == '102700' and n.write("
old style
new style
") locals = {} entry_chunks = [x for x in chunks if x['entry'] == e] entry_chunk_types = dict([(x['type'],1) for x in entry_chunks]).keys() for ect in entry_chunk_types: locals[ect] = '\n'.join( [template(x['type'],x) for x in entry_chunks if x['type'] == ect]) locals['entry'] = e page = template('page',locals) n.write('%s