1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | from twisted.web import resource, server from persist import Records from webloglib import log_fields, TOP, ROW, END, COLOR import webloglib as wll records = registry.getComponent(Records) if not records: records = Records() registry.setComponent(Records, records) class Resource(resource.Resource): def render(self, request): request.write(TOP) odd = 0 for rec in records.getNew(): print rec hit = [field.strip('"') for field in log_fields(rec)] if hit[wll.status]=='200' and hit[wll.referrer]!='-': resource = hit[wll.request].split()[1] referrer = hit[wll.referrer].replace('&',' &') request.write(ROW % (COLOR[odd],referrer,resource)) odd = not odd request.write(END) request.finish() return server.NOT_DONE_YET resource = Resource() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | class Counter: def __init__(self): self.value = 0 def increment(self): self.value += 1 def getValue(self): return self.value class Records: def __init__(self, log_name='../access-log'): self.log = open(log_name) self.recs = self.log.readlines() def getNew(self): self.recs.extend(self.log.readlines()) self.recs = self.recs[-35:] return self.recs |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |