summaryrefslogtreecommitdiff
path: root/add.py
blob: b85a9d43dddc169d8a48d91b1047216d07a48d70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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")