#!/usr/bin/env python import cgi import cgitb;cgitb.enable() import datetime import os import sajax1 WALLFILE = '/tmp/wall.html' if not os.path.exists(WALLFILE): fh = open(WALLFILE, 'w') fh.close() def colourify_ip(ip): colour = ''.join(['%02x' % int(part) for part in ip.split('.')[-3:]]) return colour def add_line(msg): f = open("/tmp/wall.html","a") dt = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") msg = cgi.escape(msg) remote = os.environ['REMOTE_ADDR'] colour = colourify_ip(remote) f.write('%(dt)s %(msg)s
\n' % locals()) f.close() def refresh(): f = open("/tmp/wall.html") return '\n'.join(list(f)[-25:]) sajax1.sajax_init() sajax1.sajax_export(refresh, add_line) sajax1.sajax_handle_client_request() print """ PyWall Sajax - Wall Example
Loading..
""" % locals()