Skip to content

Commit 392e614

Browse files
committed
updated "MyJoined"
1 parent d5fc326 commit 392e614

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def post(self):
101101
api.add_resource(Search, '/search', endpoint='Search')
102102
api.add_resource(Join, '/join', endpoint='Join')
103103
api.add_resource(MyPublished, '/my/published', endpoint='MyPublished')
104-
#api.add_resource(MyJoined, '/my/joined', endpoint='MyJoined')
104+
api.add_resource(MyJoined, '/my/joined', endpoint='MyJoined')
105105
api.add_resource(TestSearch, '/test/search', endpoint='testsearch')
106106

107107

users.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,45 @@ def post(self):
150150
"sql": sql,
151151
"data": dat
152152
# "result": float(args["rate"]*100)
153+
}
154+
155+
156+
class MyJoined(Resource):
157+
def get(self):
158+
return 1
159+
160+
def post(self):
161+
parser = reqparse.RequestParser() # 新建parser实例
162+
# 向parser实例中添加rate参数,并加以配置
163+
# parser.add_argument('rate', type=float, help='Rate cannot be converted')
164+
parser.add_argument('username')
165+
166+
# 将请求中传过来的参数存到args中
167+
args = parser.parse_args()
168+
# 将请求参数中的rate的值加以计算,并返回
169+
username = pymysql.escape_string(args["username"])
170+
db = pymysql.connect(host=Q_HOST, port=Q_PORT, user=Q_USER, passwd=Q_PASSWORD, db=Q_DB)
171+
cursor = db.cursor()
172+
sql = "SELECT * FROM participants where pname = \'%s\'" % username
173+
cursor.execute(sql)
174+
lis = cursor.fetchall()
175+
print(lis)
176+
tidlist = []
177+
for i in lis:
178+
tidlist.append(i[3])
179+
dat = {}
180+
num = 0
181+
for j in tidlist:
182+
sql = "SELECT * FROM records where tid = %d" % j
183+
cursor.execute(sql)
184+
res = cursor.fetchall()
185+
for i in res:
186+
dat0 = {"tid": i[0], "username": i[1], "stime": i[2], "etime": i[3], "location": i[4], "remarks": i[5], "joined": i[6], "finished": "已完成"}
187+
dat[num] = dat0
188+
num += 1
189+
return {
190+
"result": "ok",
191+
"sql": sql,
192+
"data": dat
193+
# "result": float(args["rate"]*100)
153194
}

0 commit comments

Comments
 (0)