def handle_query_lostlist(): json_data = json.loads(request.get_data().decode('utf-8')) keyword, date = json_data['description'], json_data['date'] print('query lost about '+keyword+' after '+date) lostlist = mc.query_sql('select objuuid,description from Lost where ownername=%s and lostdate>=%s',(' ',date)) if keyword!='': lostlist=sort_lost(lostlist,keyword) print(lostlist) return lostlist2json(lostlist)
def handle_query_getinfo(uuid): lostlist=mc.query_sql('select description,lostdate from Lost where objuuid=%s',(uuid)) if len(lostlist)==0: return 'There is no such thing!' r=lostlist[0] ld_num = 1 ldpath = basepath + uuid + '/LD' if os.path.exists(ldpath): ld_num=str(len(os.listdir(ldpath))) print(r) data = '{"description": "' + r[0] + '", "time": "' + r[1].isoformat() + '", "LD_num": "' + str(ld_num) + '"}' print(data) return data
def handle_upload_pass(): jdata = json.loads(request.get_data().decode('utf-8')) username, objuuid = jdata['username'], jdata['targetuuid'] print(username + ' thinks ' + objuuid + ' is right!') r = mc.query_sql( 'select distinct username, targetname from Messages where objuuid=%s', (objuuid)) if username == r[0][0]: targetname = r[0][1] else: targetname = r[0][0] mc.nofetchall_sql('update Lost set ownername=%s where objuuid=%s', (targetname, objuuid)) return 'True'
def handle_upload_msg(): jdata = json.loads(request.get_data().decode('utf-8')) username, objuuid, message, time = jdata['username'], jdata[ 'targetuuid'], jdata['message'], jdata['time'] r = mc.query_sql( 'select distinct username, targetname from Messages where objuuid=%s', (objuuid)) if len(r) == 0: r = mc.query_sql( 'select distinct findername from Lost where objuuid=%s', (objuuid)) if len(r) == 0: return 'True' if username == r[0][0]: targetname = r[0][1] else: targetname = r[0][0] print( username + ' sent ' + message + ' to ' + targetname + ' about ' + objuuid + 'at time:', time) mc.nofetchall_sql( 'insert into Messages(username, targetname, message,time, objuuid) values(%s,%s,%s,%s,%s)', (username, targetname, message, str(time), objuuid)) return 'True'
def handle_query_noreplylist(): jdata = json.loads(request.get_data().decode('utf-8')) username = jdata['username'] print(username + ' get noreplylist ') r = mc.query_sql( 'select distinct objuuid from Messages where targetname=%s and objuuid not in (select objuuid from Messages where username=%s)', (username, username)) data = '{"user_num":' + str(len(r)) for i, u in enumerate(r): uuid = u[0] data += ',"user' + str(i) + '":"' + uuid + '"' data += '}' print(r) print(data) return data
def handle_query_msg(): jdata = json.loads(request.get_data().decode('utf-8')) username, objuuid, time = jdata['username'], jdata['targetuuid'], jdata[ 'time'] print(username + ' get message after ' + str(time)) r = mc.query_sql( 'select message, time from Messages where objuuid=%s and targetname=%s and time>%s', (objuuid, username, str(time))) print(r) data = '{"message_num":' + str(len(r)) for i, u in enumerate(r): message, time = u[0], u[1] data += ',"message' + str(i) + '":"' + message + '",' + '"time' + str( i) + '":' + str(time) data += '}' print(data) return data
def handle_query_qrcode_lost(rand): jdata = json.loads(request.get_data().decode('utf-8')) print(jdata) username, itemuuid = jdata['useruuid'], jdata['itemuuid'] sql_select=('select * from Lost where objuuid=%s and ownername=%s',(itemuuid,username)) sql_update=('update Lost set apply="1" where objuuid=%s and ownername=%s',(itemuuid,username)) r=mc.query_sql(*sql_select) if r==0: print('-'*6) print(sql_select) return send_file(blank_img,as_attachment=True) r=mc.nofetchall_sql(*sql_update) if r==0: print('bad update') code='fetc'+itemuuid # qrcode.make(code).resize(qrcode_size).save(qrimg_path) qrcode.make(code).save(qrimg_path) return send_file(qrimg_path,as_attachment=True)
def handle_query_notapplied(username): lostlist=mc.query_sql('select objuuid from Lost where ownername=%s and apply="0"',(username)) return lostlist2json(lostlist)
def handle_query_available(username): lostlist=mc.query_sql('select objuuid from Lost where ownername=%s',(username)) return lostlist2json(lostlist)