#python
import time
from TheMingServer import Constants, Lib3
consts = Constants()
files_dir = consts.FILES_DIR
SCRIPT = consts.CGI_NAME
# note that ming.cgi debug does not carry into pypage execution
debug = 0
lib = Lib3.Lib3(debug)

lib.prn("FILES_DIR",files_dir)

NOTATE = files_dir + os.sep + "gq.notate"
FILE = files_dir + os.sep + "gq.response"
note_dict = lib.get_dict(NOTATE)
key = note_dict.keys()[0]
note_dict = note_dict[key]
lib.prn("note_dict", note_dict)

id = note_dict["comment"]
text = note_dict["note"]

file_dict = lib.get_dict(FILE)
dates = file_dict.keys()
lib.prn("file_dict", file_dict)

for date in dates:
	dict = file_dict[date]
	if dict["id"] == id:
		dict["comment_text"] = dict["comment_text"] + "\n---reply---\n" + text

lib.write_data(file_dict, FILE)
write('''<p> Your reply was appended succesfully. <br/>
You should now be redirected to the
<a href="%s?page=sites/ming-cgi/server/open/response/result">Comments page</a>.
</p>''' % SCRIPT)
write('''<meta HTTP-EQUIV="Refresh" CONTENT="0;
URL=%s?page=sites/ming-cgi/server/open/response/result">''' % SCRIPT)
