#python

import os, sys, time

# note that ming.cgi's debug does not carry into pypage execution
debug = 0

def cgi_init():
	"""
	assumes 'data' and 'cgi-bin' are peer directories
	"""
	global l, c, files_dir, SCRIPT
	current = sys.path[0]
	consts = current.split(os.sep)
	consts = os.sep.join(consts[:consts.index("data")])+os.sep+"cgi-bin"+os.sep+"TheMingServer"
	sys.path.append(consts)

	import Lib3
	l = Lib3.Lib3(debug)
	import Constants
	c = Constants.Constants()
	files_dir = os.path.join(c.FILES_DIR)
	SCRIPT = c.CGI_NAME
	return

cgi_init()
BACK = '<p>back to the <a href="%s?page=sites/ming-cgi/server/index">main page</a>' % SCRIPT
l.prn("FILES_DIR",files_dir)

file_dict = l.get_dict(files_dir+os.sep+"gq.response")
l.prn("file_dict",file_dict)
dates = file_dict.keys()
dates.sort()
dates.reverse()
for date in dates:
	dict = file_dict[date]
	try:
		name = dict["author"]
		text = dict["comment_text"]
		title= dict["title"]
	except:
		continue
	print "\n <!-- %s -->" % title	
	print "<p> %s - %s (%s) " % (name, title, time.ctime(float(dict["stamp"])))
	text = text.replace("\n", "<br>")
	print "<p>"+text
	print "<hr align=left width=25%>"

print BACK


	

