Skip to content

Commit 9ecb11b

Browse files
committed
Merge pull request Show-Me-the-Code#64 from Show-Me-the-Code/revert-62-master
Revert "Complete 0000-0003"
2 parents 06fe152 + a9371a2 commit 9ecb11b

File tree

4 files changed

+192
-0
lines changed

4 files changed

+192
-0
lines changed

NKUCodingCat/0024/0024.sql

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# SQL-Front 5.1 (Build 4.16)
2+
3+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE */;
4+
/*!40101 SET SQL_MODE='NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */;
5+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES */;
6+
/*!40103 SET SQL_NOTES='ON' */;
7+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS */;
8+
/*!40014 SET UNIQUE_CHECKS=0 */;
9+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS */;
10+
/*!40014 SET FOREIGN_KEY_CHECKS=0 */;
11+
12+
13+
# Host: localhost Database: 0024
14+
# ------------------------------------------------------
15+
# Server version 5.5.38
16+
17+
DROP DATABASE IF EXISTS `0024`;
18+
CREATE DATABASE `0024` /*!40100 DEFAULT CHARACTER SET utf8 */;
19+
USE `0024`;
20+
21+
#
22+
# Source for table code
23+
#
24+
25+
DROP TABLE IF EXISTS `code`;
26+
CREATE TABLE `code` (
27+
`id` int(20) NOT NULL DEFAULT '0',
28+
`to` text NOT NULL
29+
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
30+
31+
#
32+
# Dumping data for table code
33+
#
34+
35+
LOCK TABLES `code` WRITE;
36+
/*!40000 ALTER TABLE `code` DISABLE KEYS */;
37+
INSERT INTO `code` VALUES (13,'haiohpd');
38+
INSERT INTO `code` VALUES (14,'daduwwg');
39+
INSERT INTO `code` VALUES (9,'7');
40+
INSERT INTO `code` VALUES (11,'9');
41+
/*!40000 ALTER TABLE `code` ENABLE KEYS */;
42+
UNLOCK TABLES;
43+
44+
#
45+
# Source for table max
46+
#
47+
48+
DROP TABLE IF EXISTS `max`;
49+
CREATE TABLE `max` (
50+
`pro` varchar(255) DEFAULT NULL,
51+
`max` int(11) NOT NULL
52+
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
53+
54+
#
55+
# Dumping data for table max
56+
#
57+
58+
LOCK TABLES `max` WRITE;
59+
/*!40000 ALTER TABLE `max` DISABLE KEYS */;
60+
INSERT INTO `max` VALUES ('max',15);
61+
/*!40000 ALTER TABLE `max` ENABLE KEYS */;
62+
UNLOCK TABLES;
63+
64+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
65+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
66+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
67+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;

NKUCodingCat/0024/SQLIO.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#coding=utf-8
2+
import time, os, json, MySQLdb, HTMLParser, cgi
3+
def SQL_init():
4+
db = MySQLdb.connect("127.0.0.1","root","root","0024" )
5+
return db.cursor()
6+
def SQL_max(new=None):
7+
cursor = SQL_init()
8+
if new != None:
9+
sql="""UPDATE `max` SET `max`=%d WHERE `pro`='max'"""%new
10+
cursor.execute(sql)
11+
return True
12+
else:
13+
sql="""SELECT * FROM `max` WHERE `pro`='max'"""
14+
cursor.execute(sql)
15+
max = cursor.fetchall()[0][1]
16+
SQL_max(max+1)
17+
return max
18+
def SQL_in(task):
19+
max = SQL_max()
20+
cursor = SQL_init()
21+
sql = """INSERT INTO `code` SET `id`=%d,`to`='%s';"""%(max, task)
22+
cursor.execute(sql)
23+
return True
24+
def SQL_out():
25+
cursor = SQL_init()
26+
sql = """SELECT * FROM `code`"""
27+
cursor.execute(sql)
28+
return cursor.fetchall()
29+
def SQL_del(id):
30+
cursor = SQL_init()
31+
sql = """DELETE FROM `code` WHERE `id`=%d"""%id
32+
cursor.execute(sql)
33+
return json.dumps(cursor.fetchall())
34+
#-----------
35+
Temp = """
36+
<tr>
37+
<td class="task">%s</td>
38+
<td class="manage">
39+
<div align="center">
40+
<input type="submit" name="id-%d" id="delete" value="删除" />
41+
</div></td>
42+
</tr>
43+
"""
44+
45+
46+
def PageMake():
47+
Data = SQL_out()
48+
All = ""
49+
Data = sorted(Data,key=lambda a:a[0] )
50+
for i in Data:
51+
#print i
52+
All+=Temp%(str(i[1]),int(i[0]))
53+
return All

NKUCodingCat/0024/main.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#coding=utf-8
2+
const = """
3+
<!DOCTYPE html>
4+
<html lang="zh-cn">
5+
<head>
6+
<meta charset="utf-8">
7+
<link type="text/css" rel="stylesheet" href="./static/css.css" />
8+
</head>
9+
10+
<body>
11+
<h1>TodoList应用演示</h1>
12+
13+
<form action="" method="post">
14+
15+
<table>
16+
<tr>
17+
<td class="task_h"><div align="center">任务</div></td>
18+
<td class="manage_h"><div align="center">管理</div></td>
19+
</tr>
20+
21+
{0}
22+
</table>
23+
<br>
24+
<textarea name="newtask" id="newtask" maxlength="500"></textarea>
25+
<input type="submit" name="new" id="submit" value="创建新任务" />
26+
</form>
27+
28+
29+
</body>
30+
</html>
31+
"""
32+
33+
34+
from bottle import static_file,route, run, post, request, redirect, error
35+
import os, urllib,re,json,time
36+
Root = os.path.split(os.path.realpath(__file__))[0]+"/static/"
37+
import SQLIO
38+
39+
@route('/todo')
40+
def index():
41+
return const.format(SQLIO.PageMake(),)
42+
@post('/todo')
43+
def Accept():
44+
Req = request.body.read()
45+
L = re.split("&",Req)
46+
M = {}
47+
for i in L:
48+
A = re.split("=",i)
49+
M[A[0]] = urllib.unquote(A[1])
50+
for j in M.keys():
51+
if re.findall("id-",j):
52+
SQLIO.SQL_del(int(j[3:]))
53+
redirect('/todo', 302)
54+
try:
55+
type = M["new"]
56+
newtask = M["newtask"]
57+
except:
58+
redirect('/error', 404)
59+
if newtask != "":
60+
SQLIO.SQL_in(newtask)
61+
redirect('/todo', 302)
62+
else:
63+
return "=.=所以你想添加什么任务呀"
64+
65+
@route('/error')
66+
def err():
67+
return "虽然不知道你在干什么但是触发了服务器错误呢"
68+
@route('/static/<filename>')
69+
def server_static(filename):
70+
return static_file(filename, root=Root)
71+
run(host='localhost',port=8080)

NKUCodingCat/0024/static/css.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)