From 7ca80e57f06922e464626c7a6a1d7965e716b53f Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 13 Jul 2018 21:53:49 +0800 Subject: update --- add.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 add.py (limited to 'add.py') diff --git a/add.py b/add.py new file mode 100644 index 0000000..b85a9d4 --- /dev/null +++ b/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