Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions NKUCodingCat/0024/0024.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# SQL-Front 5.1 (Build 4.16)

/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE */;
/*!40101 SET SQL_MODE='NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES */;
/*!40103 SET SQL_NOTES='ON' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS */;
/*!40014 SET FOREIGN_KEY_CHECKS=0 */;


# Host: localhost Database: 0024
# ------------------------------------------------------
# Server version 5.5.38

DROP DATABASE IF EXISTS `0024`;
CREATE DATABASE `0024` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `0024`;

#
# Source for table code
#

DROP TABLE IF EXISTS `code`;
CREATE TABLE `code` (
`id` int(20) NOT NULL DEFAULT '0',
`to` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

#
# Dumping data for table code
#

LOCK TABLES `code` WRITE;
/*!40000 ALTER TABLE `code` DISABLE KEYS */;
INSERT INTO `code` VALUES (13,'haiohpd');
INSERT INTO `code` VALUES (14,'daduwwg');
INSERT INTO `code` VALUES (9,'7');
INSERT INTO `code` VALUES (11,'9');
/*!40000 ALTER TABLE `code` ENABLE KEYS */;
UNLOCK TABLES;

#
# Source for table max
#

DROP TABLE IF EXISTS `max`;
CREATE TABLE `max` (
`pro` varchar(255) DEFAULT NULL,
`max` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

#
# Dumping data for table max
#

LOCK TABLES `max` WRITE;
/*!40000 ALTER TABLE `max` DISABLE KEYS */;
INSERT INTO `max` VALUES ('max',15);
/*!40000 ALTER TABLE `max` ENABLE KEYS */;
UNLOCK TABLES;

/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
53 changes: 53 additions & 0 deletions NKUCodingCat/0024/SQLIO.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#coding=utf-8
import time, os, json, MySQLdb, HTMLParser, cgi
def SQL_init():
db = MySQLdb.connect("127.0.0.1","root","root","0024" )
return db.cursor()
def SQL_max(new=None):
cursor = SQL_init()
if new != None:
sql="""UPDATE `max` SET `max`=%d WHERE `pro`='max'"""%new
cursor.execute(sql)
return True
else:
sql="""SELECT * FROM `max` WHERE `pro`='max'"""
cursor.execute(sql)
max = cursor.fetchall()[0][1]
SQL_max(max+1)
return max
def SQL_in(task):
max = SQL_max()
cursor = SQL_init()
sql = """INSERT INTO `code` SET `id`=%d,`to`='%s';"""%(max, task)
cursor.execute(sql)
return True
def SQL_out():
cursor = SQL_init()
sql = """SELECT * FROM `code`"""
cursor.execute(sql)
return cursor.fetchall()
def SQL_del(id):
cursor = SQL_init()
sql = """DELETE FROM `code` WHERE `id`=%d"""%id
cursor.execute(sql)
return json.dumps(cursor.fetchall())
#-----------
Temp = """
<tr>
<td class="task">%s</td>
<td class="manage">
<div align="center">
<input type="submit" name="id-%d" id="delete" value="删除" />
</div></td>
</tr>
"""


def PageMake():
Data = SQL_out()
All = ""
Data = sorted(Data,key=lambda a:a[0] )
for i in Data:
#print i
All+=Temp%(str(i[1]),int(i[0]))
return All
71 changes: 71 additions & 0 deletions NKUCodingCat/0024/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#coding=utf-8
const = """
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<link type="text/css" rel="stylesheet" href="./static/css.css" />
</head>

<body>
<h1>TodoList应用演示</h1>

<form action="" method="post">

<table>
<tr>
<td class="task_h"><div align="center">任务</div></td>
<td class="manage_h"><div align="center">管理</div></td>
</tr>

{0}
</table>
<br>
<textarea name="newtask" id="newtask" maxlength="500"></textarea>
<input type="submit" name="new" id="submit" value="创建新任务" />
</form>


</body>
</html>
"""


from bottle import static_file,route, run, post, request, redirect, error
import os, urllib,re,json,time
Root = os.path.split(os.path.realpath(__file__))[0]+"/static/"
import SQLIO

@route('/todo')
def index():
return const.format(SQLIO.PageMake(),)
@post('/todo')
def Accept():
Req = request.body.read()
L = re.split("&",Req)
M = {}
for i in L:
A = re.split("=",i)
M[A[0]] = urllib.unquote(A[1])
for j in M.keys():
if re.findall("id-",j):
SQLIO.SQL_del(int(j[3:]))
redirect('/todo', 302)
try:
type = M["new"]
newtask = M["newtask"]
except:
redirect('/error', 404)
if newtask != "":
SQLIO.SQL_in(newtask)
redirect('/todo', 302)
else:
return "=.=所以你想添加什么任务呀"

@route('/error')
def err():
return "虽然不知道你在干什么但是触发了服务器错误呢"
@route('/static/<filename>')
def server_static(filename):
return static_file(filename, root=Root)
run(host='localhost',port=8080)
1 change: 1 addition & 0 deletions NKUCodingCat/0024/static/css.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.