summaryrefslogtreecommitdiff
path: root/add.py
diff options
context:
space:
mode:
Diffstat (limited to 'add.py')
-rw-r--r--add.py63
1 files changed, 63 insertions, 0 deletions
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 = """
+ <html>
+ <head>
+ <meta http-equiv="refresh" content="0;url={0}/page.py">
+ </head>
+ </html>
+ """.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 = """
+ <html>
+ <head>
+ <meta http-equiv="refresh" content="0;url={0}/page.py">
+ </head>
+ </html>
+ """.format(_url)
+ print(redirect)
+else:
+ print("Invalid action") \ No newline at end of file