Skip to content

Commit a3301ef

Browse files
committed
0023 Complete
妈呀好累…… 我想静静 也别问我静静是谁
1 parent f6287cc commit a3301ef

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

NKUCodingCat/0023/main.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#coding=utf-8
2+
from bottle import static_file,route, run, post, request, redirect
3+
import os, makeweb, urllib,re,json,time
4+
Root = os.path.split(os.path.realpath(__file__))[0]+"/static/"
5+
Const = """
6+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
7+
<html xmlns="http://www.w3.org/1999/xhtml">
8+
<head>
9+
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
10+
<title>无标题文档</title>
11+
<link type="text/css" rel="stylesheet" href="./static/css.css" />
12+
13+
</head>
14+
15+
<body>
16+
<div id="1">
17+
<form id="form1" name="form1" method="post" action="">
18+
<label>名字
19+
<input id="name" type="text" name="textfield" tabindex="0" />
20+
</label>
21+
<p>
22+
<label>评论
23+
<textarea name="textarea" tabindex="1" style="height: 89px; width: 350px;"></textarea>
24+
</label>
25+
</p>
26+
<p>
27+
<label>
28+
<input id="Submit" type="submit" name="Submit" value="提交" />
29+
</label>
30+
</p>
31+
</form>
32+
</div>
33+
<div>
34+
%s
35+
</div>
36+
</body>
37+
</html>
38+
39+
"""
40+
@route('/board')
41+
def index():
42+
return Const%makeweb.Pack(makeweb.Stor_out())
43+
@post('/board')
44+
def Accept():
45+
Req = request.body.read()
46+
L = re.split("&",Req)
47+
M = {}
48+
for i in L:
49+
A = re.split("=",i)
50+
M[A[0]] = urllib.unquote(A[1])
51+
New = {}
52+
New["Name"] = M["textfield"]
53+
New["Content"] = M["textarea"]
54+
makeweb.Stor_in(New)
55+
redirect('/board', 302)
56+
57+
@route('/static/<filename>')
58+
def server_static(filename):
59+
return static_file(filename, root=Root)
60+
run(host='localhost',port=8080)

NKUCodingCat/0023/makeweb.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import time, os, json, MySQLdb, HTMLParser, cgi
2+
3+
def odd(src):
4+
return """<div class="odd">%s</div>"""%src
5+
def nor(src):
6+
return """<div class="nor">%s</div>"""%src
7+
def public(Name,TimeStamp,Content):
8+
return """<div class="text"><h3 class="NameType">%s @ %s</h3><pre>%s</pre></div>"""%(Name, time.ctime(TimeStamp),Content)
9+
def Pack(Array):
10+
Count = 1
11+
pack = ""
12+
for i in Array:
13+
if not i:
14+
continue
15+
if Count%2 == 1:
16+
pack+=odd(public(i[0],i[1],cgi.escape(i[2])))
17+
else:
18+
pack+=nor(public(i[0],i[1],cgi.escape(i[2])))
19+
Count+=1
20+
return pack
21+
#=========
22+
def SQL_init():
23+
db = MySQLdb.connect("127.0.0.1","root","root","0023" )
24+
return db.cursor()
25+
def Stor_in(New):
26+
cursor = SQL_init()
27+
sql = """INSERT INTO `code` SET `Name`='%s',`TimeStamp`=%f,`Content`='%s'"""%(New["Name"],time.time(),New["Content"])
28+
cursor.execute(sql)
29+
return "Send Comment Success!"
30+
def Stor_out(st=0,leng=50):
31+
cursor = SQL_init()
32+
sql = """SELECT * FROM `code` LIMIT %d,%d;"""%(st,(st+leng))
33+
cursor.execute(sql)
34+
return cursor.fetchall()

NKUCodingCat/0023/static/css.css

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
#form1 {
3+
background-color: #3399FF;
4+
margin-top:1em;
5+
}
6+
input#Submit{
7+
margin:1em;
8+
}
9+
input#name{
10+
margin-top:1em;
11+
margin-bottom:1em;
12+
}
13+
label{
14+
margin-left:1em;
15+
}
16+
div.odd{
17+
background-color: #FFFFFF;
18+
}
19+
div.nor{
20+
background-color: #DDDDDD;
21+
}
22+
div.nor,div.odd{
23+
margin:0px;
24+
padding:0px;
25+
border:1px;
26+
}
27+
div.text
28+
{
29+
padding-top:1em;
30+
padding-bottom:1em;
31+
padding-left:0.5em;
32+
padding-right:0.5em;
33+
}
34+
pre{padding-left:3em;}
35+
h3{padding-left:1.5em;}

0 commit comments

Comments
 (0)