-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
208 lines (124 loc) · 3.61 KB
/
test.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# -*- coding: UTF-8 -*-
import MySQLdb
import datetime
import types
from collections import OrderedDict
#添加的表名
context = {'Q':{}}
context['Q'] = OrderedDict(context['Q'])
list_sort =['ID','Title','Body','Timestamp'] #表属性
'''
nowtime =datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
IDs = [1,2,3]
Titles = ['一','二','三']
Bodys = ['一','二','三三三三skldshkdjshds']
Timestamps = [nowtime,nowtime,nowtime]
for key in list_sort:
values = eval(key+'s')
for value in values:
context['Q'].setdefault(key,[]).append(value)
'''
def details(*args):
#print args[0][0]
ks = []
for key in list_sort:
ks.append(key)
for i in range(len(ks)):
buf = args[0][i]
if type(buf) == datetime.datetime:
buf = args[0][i].strftime('%Y-%m-%d %H:%M:%S')
else:
buf = args[0][i]
#print type(buf)
context['Q'].setdefault(ks[i],[]).append(buf)
print len(context['Q']['ID'])
#print context
# 打开数据库连接
try:
db = MySQLdb.connect("localhost", "root", "wuwangjie", "blog", charset='utf8' )
except:
print "连接失败"
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# SQL 查询语句
sql = "SELECT * FROM post "
arg = []
try:
# 执行SQL语句
cursor.execute(sql)
# 获取所有记录列表
results = cursor.fetchall()
for ID in cursor:
for index in range(len(ID)):
#print ID[index]
arg.append(ID[index])
#print arg
details(arg)
arg = []
except MySQLdb.Error,e:
cursor.rollback()
db.rollback()
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
# 关闭数据库连接
db.close()
'''
import collections
context = {'Q':{}}
#context['Q'] = collections.OrderedDict()
list_sort = ['Title','Body','Timestamp']
Titles = ['1','2','3']
Bodys = ['3','2','1']
Timestamps = ['2018-04-13 22:6:11','2018-04-13 22:6:11','2018-04-13 22:6:11']
for key in list_sort:
values = eval(key+'s')
for value in values:
context['Q'].setdefault(key,[]).append(value)
for i in range(len(list_sort)):
for j in range(len(list_sort)):
print context['Q'][list_sort[j]][i]
#print context['Q']['Title']
#print sorted(context['Q'],reverse=True)
def context(list_sort,):
for title in Titles:
context['Q'].setdefault(Title,[]).append(title)
for body in Bodys:
context['Q'].setdefault(Body,[]).append(body)
for time in Timestamps:
context['Q'].setdefault(Timestamp,[]).append(time)
'''
'''
d_urls = [ ('^/index$' , 'index'),
('^/admin$' , 'admin'),
('^/admin/add.html$' , 'ADD' ),
('^/admin/post.html$' , 'ADD' )
]
static_urls = [ ('^/static/css/add.css$' , 'css' ),
('^/static/css/admin.css$' , 'css' ),
('^/static/js/getTimeStamp.js$', 'js' ),
('^/static/js/Submit.js$' , 'js' ),
('^/static/img/1.jpeg$' , 'jpeg' )
]
urls = d_urls + static_urls
print urls
context = {}
titles = 'title'
title = ['one','two','three']
title.append('four')
for t in title:
context.setdefault(titles,[]).append(t)
#context = json.dumps(context,encoding="UTF-8",ensure_ascii=False,sort_keys=False, indent=4)
#context = json.loads(context, encoding="UTF-8",ensure_ascii=False)
print context
测试用,无卵用!
from model import blog
class blog_list():
post =['Title','body','created','updated']
comment=['content','created']
#blog_list = blog_list()
def a(app,*args):
f=getattr(app,args[0][0])
print f
print args
print len(args[0])
a(blog,blog_list.post,blog_list.comment)
'''