from twisted.web import resource, server from persist import Records import webloglib as wll reload(wll) from webloglib import log_fields, COLOR from urllib import unquote_plus as uqp fieldnames = "ip timestamp request status bytes referrer agent".split() field_dict = dict(zip(fieldnames, range(7))) TOP = '''Weblog Refresher
IP Timestamp Request Status Bytes Referrer Agent
''' ROW = '%s\n' END = '
' COLOR = ['white','lightgray'] END = '''''' records = registry.getComponent(Records) if not records: records = Records() registry.setComponent(Records, records) class Resource(resource.Resource): def render(self, request): showlist = [] for field in request.args.keys(): showlist.append(field_dict[field]) checked = [""] * len(fieldnames) for n in showlist: checked[n] = 'checked' request.write(TOP % tuple(checked)) odd = 0 for rec in records.getNew(): hit = [field.strip('"') for field in log_fields(rec)] flds = '\n'.join(['%s\n'%hit[n] for n in showlist]) request.write(ROW %(COLOR[odd],uqp(flds).replace('&',' &'))) odd = not odd request.write(END) request.finish() return server.NOT_DONE_YET resource = Resource()