From d351e45604f192df6ef710d476a8e529fefa73bf Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 11 Jul 2018 22:04:43 +0800 Subject: update --- cgi-bin/add.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 cgi-bin/add.py (limited to 'cgi-bin/add.py') diff --git a/cgi-bin/add.py b/cgi-bin/add.py new file mode 100644 index 0000000..e3a7d4e --- /dev/null +++ b/cgi-bin/add.py @@ -0,0 +1,63 @@ +#!D:/Programs/Python3/python.exe +# -*- coding: utf-8 -*- +import cgi, cgitb +import pymysql +import sys, codecs +import configparser, codecs +import connect +from connect import Connect +import config +from config import Config +import path +from path import Path +import time + +sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer) +print("Content-type:text/html\n") + +form = cgi.FieldStorage() +action = form.getvalue('action') +if action == "modify": + whisper_content = form.getvalue('whisper_content') + if whisper_content == None: + whisper_content = "" + whisper_id = form.getvalue('whisper_id') + db = Connect.produce() + cursor = db.cursor() + query = "update whisper set content = '{0}' where id = {1}".format(pymysql.escape_string(whisper_content), whisper_id) + cursor.execute(query) + db.commit() + cursor.close() + db.close() + _url = Config.get("route", "url") + redirect = """ + + + + + + """.format(_url) + print(redirect) +elif action == "new": + whisper_content = form.getvalue('whisper_content') + if whisper_content == None: + whisper_content = "" + t = time.time() + db = Connect.produce() + cursor = db.cursor() + query = "insert into whisper (content, date) values ('{0}', '{1}')".format(pymysql.escape_string(whisper_content), t) + cursor.execute(query) + db.commit() + cursor.close() + db.close() + _url = Config.get("route", "url") + redirect = """ + + + + + + """.format(_url) + print(redirect) +else: + print("Invalid action") \ No newline at end of file -- cgit v1.1-26-g67d0