forked from Show-Me-the-Code/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeweb.py
More file actions
34 lines (33 loc) · 1 KB
/
makeweb.py
File metadata and controls
34 lines (33 loc) · 1 KB
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
import time, os, json, MySQLdb, HTMLParser, cgi
def odd(src):
return """<div class="odd">%s</div>"""%src
def nor(src):
return """<div class="nor">%s</div>"""%src
def public(Name,TimeStamp,Content):
return """<div class="text"><h3 class="NameType">%s @ %s</h3><pre>%s</pre></div>"""%(Name, time.ctime(TimeStamp),Content)
def Pack(Array):
Count = 1
pack = ""
for i in Array:
if not i:
continue
if Count%2 == 1:
pack+=odd(public(i[0],i[1],cgi.escape(i[2])))
else:
pack+=nor(public(i[0],i[1],cgi.escape(i[2])))
Count+=1
return pack
#=========
def SQL_init():
db = MySQLdb.connect("127.0.0.1","root","root","0023" )
return db.cursor()
def Stor_in(New):
cursor = SQL_init()
sql = """INSERT INTO `code` SET `Name`='%s',`TimeStamp`=%f,`Content`='%s'"""%(New["Name"],time.time(),New["Content"])
cursor.execute(sql)
return "Send Comment Success!"
def Stor_out(st=0,leng=50):
cursor = SQL_init()
sql = """SELECT * FROM `code` LIMIT %d,%d;"""%(st,(st+leng))
cursor.execute(sql)
return cursor.fetchall()