⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wall.py

📁 Ajax最流行书籍
💻 PY
字号:
#!/usr/bin/env pythonimport cgiimport cgitb;cgitb.enable()import datetimeimport osimport sajax1WALLFILE = '/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('<span style="color:#%(colour)s">%(dt)s</span> %(msg)s<br />\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 """<html><head>	<title>PyWall</title>	<script>"""sajax1.sajax_show_javascript()print """	var check_n = 0;		function refresh_cb(new_data) {		document.getElementById("wall").innerHTML = new_data;		document.getElementById("status").innerHTML = "Checked #" + check_n++;		setTimeout("refresh()", 1000);	}		function refresh() {		document.getElementById("status").innerHTML = "Checking..";		x_refresh(refresh_cb);	}		function add_cb() {		// we don't care..	}	function add() {		var line;		var handle;		handle = document.getElementById("handle").value;		line = document.getElementById("line").value;		if (line == "") 			return;		x_add_line("[" + handle + "] " + line, add_cb);		document.getElementById("line").value = "";	}	</script>	</head><body onload="refresh();">	<a href="http://">Sajax</a> - Wall Example<br/>		<input type="text" name="handle" id="handle" value="(name)"		onfocus="this.select()" style="width:130px;">	<input type="text" name="line" id="line" value="(enter your message here)"		onfocus="this.select()"		style="width:300px;">	<input type="button" name="check" value="Post message"		onclick="add(); return false;">	<div id="wall"></div>	<div id="status"><em>Loading..</em></div>	</body></html>""" % locals()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -