How to use jsonify method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

server.py

Source:server.py Github

copy

Full Screen

...67 return 'deny'68#easter egg 69@app.route('/love')70def love():71 return jsonify(love="megha")72@app.route('/uploadpictest')73def uploadpictest():74 return render_template("test.html")75 76@app.errorhandler(404)77def err(error):78 return "url mismatch, may be a typo"79#-80#starting point81@app.route('/signup', methods= ['GET', 'POST'])82def signup():83 try:84 password=request.values.get('password')85 emailid=request.values.get('emailid')86 chk=isValidEmail(emailid) and isValidPassword(password)87 if chk==False:88 return jsonify(error="error",msg="invalid emailid or password, password must be atleast 8 characters long")89 msg="failed"90 with sqlite3.connect("Tinder.db") as con:91 cur = con.cursor()92 cur.execute("SELECT * from Users where EmailID=?",(emailid,))93 chk = cur.fetchone()94 if chk :95 return jsonify(error="error",msg="Account is already registered with this emailId") 96 else:97 cur.execute("INSERT INTO Users (Password,EmailID) VALUES (?,?)",(password,emailid))98 con.commit()99 msg = "Record successfully added " + emailid 100 return jsonify(msg=msg)101 except:102 #con.rollback()103 msg = "error in insert operation , check if you sent both password and emailid as arguments"104 return jsonify(error="error",msg=msg)105@app.route('/login', methods= ['GET', 'POST'])106def login(): 107 try:108 password=request.values.get('password')109 emailid=request.values.get('emailid')110 with sqlite3.connect("Tinder.db") as con:111 cur = con.cursor()112 cur.execute("SELECT Password FROM Users where EmailID=?",(emailid,))113 p = cur.fetchone()114 if p == None:115 return jsonify(error="error",msg="Emailid not registered")116 if p[0] == password:117 msg = "login successful"118 key = session_key()119 with sqlite3.connect("Tinder.db") as con:120 cur = con.cursor()121 cur.execute("UPDATE Users SET SessionID = ? WHERE EmailID = ?",(key,emailid)) 122 con.commit()123 return jsonify(msg=msg,sessionid=key)124 else:125 return jsonify(error="error",msg="incorrect password for the given emailid")126 return jsonify(error="error",msg="db error")127 except:128 return jsonify(error="error",msg="login failed")129@app.route('/profile', methods= ['GET', 'POST'])130def profile():131 try:132 sessionid=request.values.get('sessionid')133 emailid=request.values.get('emailid')134 name=request.values.get('name')135 age=request.values.get('age')136 gender=request.values.get('gender')137 location=request.values.get('location')138 lookingfor=request.values.get('lookingfor')139 about=request.values.get('about')140 age=int(age)141 chk=isValidEmail(emailid) and isValidAge(age) and isValidName(name) and isValidSession(sessionid)142 if chk==False:143 return jsonify(error="error",msg='invalid emailid or age or name or sessionid')144 msg="failed"145 with sqlite3.connect("Tinder.db") as con:146 cur = con.cursor()147 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))148 chk = cur.fetchone()149 print (chk)150 if chk==None:151 return jsonify(error="error",msg="Emailid not registered")152 if chk[0] == sessionid :153 cur.execute("SELECT email from profile where email=?",(emailid,))154 print(1)155 chk = cur.fetchone()156 print(2)157 if chk:158 cur.execute("DELETE from profile where email=?",(emailid,))159 print(3)160 cur.execute("INSERT INTO profile (email,name,age,gender,location,lookingfor,about) VALUES (?,?,?,?,?,?,?)",(emailid,name,age,gender,location,lookingfor,about))161 print(4)162 con.commit()163 print(5)164 msg = "profile successfully updated for " + emailid 165 return jsonify(msg=msg)166 else:167 return jsonify(error="error",msg="Account is not registered with this emailId or invalid sessionid") 168 except:169 return jsonify(error="error",msg="Error in api request")170 171@app.route('/getprofileinfo', methods= ['GET', 'POST'])172def getprofileinfo():173 try:174 sessionid=request.values.get('sessionid')175 emailid=request.values.get('emailid')176 chk=isValidEmail(emailid) and isValidSession(sessionid)177 if chk==False:178 return jsonify(error="error",msg='invalid emailid or sessionid')179 msg="failed"180 with sqlite3.connect("Tinder.db") as con:181 cur = con.cursor()182 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))183 chk = cur.fetchone()184 if chk == None:185 return jsonify(error="error",msg="Emailid is not registered")186 if chk[0] == sessionid :187 cur.execute("SELECT * from profile where email=?",(emailid,))188 chk = cur.fetchone()189 return jsonify(emailid=chk[0],name=chk[1],age=chk[2],gender=chk[3],location=chk[4],lookingfor=chk[5],about=chk[6],zraw=chk)190 else:191 return jsonify(error="error",msg="Invalid sessionid") 192 except:193 msg = "error in insert operation"194 return jsonify(error="error",msg=msg)195@app.route('/suggest', methods= ['GET', 'POST'])196def suggest():197 try:198 sessionid=request.values.get('sessionid')199 emailid=request.values.get('emailid')200 chk=isValidEmail(emailid) and isValidSession(sessionid)201 if chk==False:202 return jsonify(error="error",msg='invalid emailid or sessionid')203 msg="failed"204 with sqlite3.connect("Tinder.db") as con:205 cur = con.cursor()206 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))207 chk = cur.fetchone()208 if chk == None:209 return jsonify(error="error",msg="Emailid is not registered")210 if chk[0] == sessionid :211 cur.execute("SELECT location,lookingfor from profile where email=?",(emailid,))212 chk = cur.fetchone()213 locate, look = chk214 cur.execute("SELECT * from profile where gender=?",(look,))215 suggest=cur.fetchall()216 return jsonify(suggestion=suggest)217 else:218 return jsonify(error="error",msg="Invalid sessionid") 219 except:220 msg = "Emailid not registered"221 return jsonify(error="error",msg=msg)222@app.route('/uploade', methods = ['GET', 'POST'])223def upload():224 try:225 if request.method == "POST":226 emailid=request.values.get('emailid')227 sessionid=request.values.get('sessionid')228 chk=isValidEmail(emailid) and isValidSession(sessionid)229 if chk==False:230 return jsonify(error="error",msg='invalid emailid or sessionid')231 with sqlite3.connect("Tinder.db") as con:232 cur = con.cursor()233 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))234 chk = cur.fetchone()235 if chk==None:236 return jsonify(error="error",msg="Emailid is not registered")237 if chk[0] == sessionid :238 f = request.files['file']239 if f:240 filename=str((emailid.split('@'))[0])+'.jpg'241 dir= os.path.join(os.getcwd(),'images') 242 f.save(os.path.join(dir,filename))243 f.save(secure_filename(f.filename))244 return jsonify(msg="file uploaded successfully")245 else:246 return jsonify(error="error",msg="file not sent")247 else:248 return jsonify(error="error",msg='invalid sessionid')249 else:250 return jsonify(error="error",msg="send via post request")251 except:252 return jsonify(error="error",msg="Error in api request")253@app.route('/image')#image sample254def image():255 try:256 emailid=request.values.get('emailid')257 print(emailid)258 filename=str((emailid.split('@'))[0])259 for name in os.listdir('images'):260 if filename in name:261 print ("Found %s" % filename)262 filename=name263 return send_file('images/'+filename,mimetype='image/gif')264 else:265 print (os.listdir('images'))266 return jsonify(error="error",msg="profile pic not updated")267 except:268 return jsonify(error="error",msg="Error in api request")269@app.route('/sqlite')#image sample270def sqlite():271 try:272 sql=request.values.get('sql')273 admin=request.values.get('ar')274 if admin=="password here--CRITICAL":275 with sqlite3.connect("Tinder.db") as con:276 cur = con.cursor()277 cur.execute(sql)278 chk=cur.fetchall()279 return jsonify(data=chk)280 # res=[]281 # for i in chk:282 # res.append(list(i))283 # return str(res)284 else:285 return abort(404)286 except:287 return jsonify(error="error",msg="Error in api request")288@app.route('/allusers', methods= ['GET', 'POST'])289def allusers():290 try:291 sessionid=request.values.get('sessionid')292 emailid=request.values.get('emailid')293 chk=isValidEmail(emailid) and isValidSession(sessionid)294 if chk==False:295 return jsonify(error="error",msg='invalid emailid or sessionid')296 msg="failed"297 with sqlite3.connect("Tinder.db") as con:298 cur = con.cursor()299 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))300 chk = cur.fetchone()301 if chk == None:302 return jsonify(error="error",msg="Emailid is not registered")303 if chk[0] == sessionid :304 cur.execute("SELECT * from profile")305 suggest=cur.fetchall()306 return jsonify(usersList=suggest)307 else:308 return jsonify(error="error",msg="Invalid sessionid") 309 except:310 msg = "Emailid not registered"311 return jsonify(error="error",msg=msg)312@app.route('/logout', methods= ['GET', 'POST'])313def logout():314 try:315 sessionid=request.values.get('sessionid')316 emailid=request.values.get('emailid')317 chk=isValidEmail(emailid) and isValidSession(sessionid)318 if chk==False:319 return jsonify(error="error",msg='invalid emailid or sessionid')320 msg="failed"321 with sqlite3.connect("Tinder.db") as con:322 cur = con.cursor()323 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))324 chk = cur.fetchone()325 if chk == None:326 return jsonify(error="error",msg="Emailid is not registered")327 if chk[0] == sessionid :328 cur.execute("UPDATE Users SET SessionID = ? WHERE EmailID = ?",(sessionid+session_key(),emailid))329 return jsonify(msg="Logged out successfully")330 else:331 return jsonify(error="error",msg="Invalid sessionid") 332 except:333 msg = "Emailid not registered"334 return jsonify(error="error",msg=msg)335@app.route('/profilechange', methods= ['GET', 'POST'])336def profilechange():337 try:338 sessionid=request.values.get('sessionid')339 emailid=request.values.get('emailid')340 name=request.values.get('name')341 age=request.values.get('age')342 gender=request.values.get('gender')343 about=request.values.get('about')344 age=int(age)345 chk=isValidEmail(emailid) and isValidAge(age) and isValidName(name) and isValidSession(sessionid)346 if chk==False:347 return jsonify(error="error",msg='invalid emailid or age or name or sessionid')348 msg="failed"349 with sqlite3.connect("Tinder.db") as con:350 cur = con.cursor()351 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))352 chk = cur.fetchone()353 print (chk)354 if chk==None:355 return jsonify(error="error",msg="Emailid not registered")356 if chk[0] == sessionid :357 cur.execute("SELECT email from profile where email=?",(emailid,))358 chk = cur.fetchone()359 if chk:360 cur.execute("SELECT * from profile where email=?",(emailid,))361 chk = cur.fetchone()362 print (chk)363 location=chk[4]364 lookingfor=chk[5]365 cur.execute("DELETE from profile where email=?",(emailid,))#rollback must be used for consistency366 cur.execute("INSERT INTO profile (email,name,age,gender,location,about,lookingfor) VALUES (?,?,?,?,?,?,?)",(emailid,name,age,gender,location,about,lookingfor))367 con.commit()368 msg = "profile successfully updated for " + emailid 369 return jsonify(msg=msg)370 else:371 return jsonify(error="error",msg="Profile missing")372 else:373 return jsonify(error="error",msg="Account is not registered with this emailId or invalid sessionid") 374 except:375 return jsonify(error="error",msg="Error in api request")376@app.route('/profilelook', methods= ['GET', 'POST'])377def profilelook():378 try:379 sessionid=request.values.get('sessionid')380 emailid=request.values.get('emailid')381 lookingfor=request.values.get('lookingfor')382 location=request.values.get('location')383 chk=isValidEmail(emailid) and isValidSession(sessionid)384 if chk==False:385 return jsonify(error="error",msg='invalid emailid or sessionid')386 msg="failed"387 with sqlite3.connect("Tinder.db") as con:388 cur = con.cursor()389 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))390 chk = cur.fetchone()391 print (chk)392 if chk==None:393 return jsonify(error="error",msg="Emailid not registered")394 if chk[0] == sessionid :395 cur.execute("SELECT email from profile where email=?",(emailid,))396 print(1)397 chk = cur.fetchone()398 print(2)399 if chk:400 cur.execute("SELECT * from profile where email=?",(emailid,))401 chk = cur.fetchone()402 print (chk)403 emailid=chk[0]404 name=chk[1]405 age=chk[2]406 gender=chk[3]407 about=chk[6]408 cur.execute("DELETE from profile where email=?",(emailid,))#rollback must be used for consistency409 cur.execute("INSERT INTO profile (email,name,age,gender,location,about,lookingfor) VALUES (?,?,?,?,?,?,?)",(emailid,name,age,gender,location,about,lookingfor))410 con.commit()411 msg = "profile successfully updated for " + emailid 412 return jsonify(msg=msg)413 else:414 return jsonify(error="error",msg="Profile missing")415 else:416 return jsonify(error="error",msg="Account is not registered with this emailId or invalid sessionid") 417 except:418 return jsonify(error="error",msg="Error in api request")419@app.route('/opinion', methods= ['GET', 'POST'])420def opinion():421 try:422 sessionid=request.values.get('sessionid')423 emailid=request.values.get('emailid')424 target=request.values.get('target')425 opinion=request.values.get('opinion')426 chk=isValidEmail(emailid) and isValidSession(sessionid)427 print (opinion)428 if opinion not in [0,1,'0','1']:429 return jsonify(error="error",msg="opinion must be 0 for hate and 1 for love not anything else")430 if chk==False:431 return jsonify(error="error",msg='invalid emailid or sessionid')432 chk=isValidEmail(target)433 if chk==False:434 return jsonify(error="error",msg='invalid target emailid') 435 msg="failed"436 with sqlite3.connect("Tinder.db") as con:437 cur = con.cursor()438 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))439 chk = cur.fetchone()440 print (chk)441 if chk==None:442 return jsonify(error="error",msg="Emailid not registered")443 if chk[0] == sessionid :444 cur.execute("SELECT EmailID from Users where EmailID=?",(target,))445 print(1)446 chk = cur.fetchone()447 print(2) 448 if chk:449 cur.execute("SELECT email from love where email=?",(emailid,))450 chk = cur.fetchone()451 if chk:452 cur.execute("DELETE from love where email=?",(emailid,))#rollback must be used for consistency453 cur.execute("INSERT INTO love(email,target,opinion) VALUES (?,?,?)",(emailid,target,opinion)) 454 con.commit()455 msg = "opinion successfully updated for " + emailid 456 return jsonify(msg=msg)457 else:458 return jsonify(error="error",msg="Target does not exist")459 else:460 return jsonify(error="error",msg="Account is not registered with this emailId or invalid sessionid") 461 except:462 return jsonify(error="error",msg="Error in api request")463@app.route('/matches', methods= ['GET', 'POST'])464def matches():465 try:466 sessionid=request.values.get('sessionid')467 emailid=request.values.get('emailid')468 chk=isValidEmail(emailid) and isValidSession(sessionid)469 if chk==False:470 return jsonify(error="error",msg='invalid emailid or sessionid') 471 msg="failed"472 with sqlite3.connect("Tinder.db") as con:473 cur = con.cursor()474 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))475 chk = cur.fetchone()476 if chk==None:477 return jsonify(error="error",msg="Emailid not registered")478 if chk[0] == sessionid :479 if chk:480 cur.execute("SELECT email from love where target=? and opinion=?",(emailid,1))481 chk = cur.fetchall()482 if chk:483 msg = "Congrats!! Matches found " + emailid 484 return jsonify(msg=msg,matches=chk)485 else:486 return jsonify(error="error",msg="No matches found")487 else:488 return jsonify(error="error",msg="Target does not exist")489 else:490 return jsonify(error="error",msg="Account is not registered with this emailId or invalid sessionid") 491 except:492 return jsonify(error="error",msg="Error in api request")493@app.route('/delete', methods= ['GET', 'POST'])494def delete():495 try:496 password=request.values.get('password')497 emailid=request.values.get('emailid')498 chk=isValidEmail(emailid) and isValidSession(sessionid)499 if chk==False:500 return jsonify(error="error",msg='invalid emailid or sessionid')501 with sqlite3.connect("Tinder.db") as con:502 cur = con.cursor()503 cur.execute("SELECT Password FROM Users where EmailID=?",(emailid,))504 p = cur.fetchone()505 if p == None:506 return jsonify(error="error",msg="Emailid not registered")507 if p[0] == password:508 with sqlite3.connect("Tinder.db") as con:509 cur = con.cursor()510 cur.execute("DELETE from Users WHERE EmailID = ?",(emailid,)) 511 con.commit()512 return jsonify(msg="Account deleted, ;-(")513 else:514 return jsonify(error="error",msg="incorrect password for the given emailid")515 return jsonify(error="error",msg="db error")516 except:517 return jsonify(error="error",msg="Account deletion failed")518@app.route('/message', methods= ['GET', 'POST'])519def message():520 try:521 sessionid=request.values.get('sessionid')522 emailid=request.values.get('emailid')523 reciever=request.values.get('reciever')524 message=request.values.get('message') 525 chk=isValidEmail(emailid) and isValidEmail(reciever) and isValidSession(sessionid)526 if chk==False:527 return jsonify(error="error",msg='invalid emailid or invalid recipient or sessionid')528 msg="failed"529 if emailid==reciever:530 return jsonify(error="error",msg="Cannot send message to yourself")531 with sqlite3.connect("Tinder.db") as con:532 cur = con.cursor()533 cur.execute("SELECT EmailID from Users where EmailID=?",(reciever,))534 chk=cur.fetchone()535 if chk==None:536 return jsonify(error="error",msg="recipient is not registered")537 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))538 chk = cur.fetchone()539 if chk==None:540 return jsonify(error="error",msg="Emailid not registered")541 print (chk,32123,chk[0])542 if chk[0] == sessionid :543 timer=time.ctime()544 cur.execute("SELECT block from Block where user=?",(emailid,))545 ub=cur.fetchall()546 cur.execute("SELECT block from Block where block=?",(emailid,))547 rb=cur.fetchall()548 print (ub,rb)549 if ub!=[]:550 if reciever in ub[0]:551 return jsonify(error="error",msg="You have blocked the user")552 if rb!=[]:553 if emailid in rb[0]:554 return jsonify(error="error",msg="Recipient has blocked you")555 cur.execute("INSERT INTO message (sender,recipient,time,message) VALUES (?,?,?,?)",(emailid,reciever,timer,message))556 con.commit()557 msg = "message recieved from " + emailid + " to " + reciever558 return jsonify(msg=msg)559 else:560 return jsonify(error="error",msg="Account is not registered with this emailId or invalid sessionid") 561 except:562 return jsonify(error="error",msg="Error in api request")563 564@app.route('/messageDelete', methods= ['GET', 'POST'])565def messageDelete():566 try:567 sessionid=request.values.get('sessionid')568 emailid=request.values.get('emailid')569 messageID=request.values.get('messageID')570 message=request.values.get('message') 571 chk=isValidEmail(emailid) and isValidSession(sessionid)572 if chk==False:573 return jsonify(error="error",msg='invalid emailid or sessionid')574 msg="failed"575 with sqlite3.connect("Tinder.db") as con:576 cur = con.cursor()577 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))578 chk = cur.fetchone()579 if chk==None:580 return jsonify(error="error",msg="Emailid not registered")581 if chk[0] == sessionid :582 timer=time.ctime()583 cur.execute("SELECT deletion,recipient,sender from message where messageID=? and message=?",(messageID,message))584 chk=cur.fetchone()585 print (chk)586 if chk==None:587 return jsonify(error="error",msg="check for appropriate messageID and message")588 if emailid in chk:589 pass590 else:591 return jsonify(error="error",msg="Message is not associated with this emailid")592 if chk[0]==None or chk[0]=="":593 info=emailid594 cur.execute("UPDATE message SET deletion = ? WHERE messageID = ?",(info,messageID))595 con.commit()596 msg = "message deleted for " + emailid597 return jsonify(msg=msg)598 if chk[0]==emailid:599 return jsonify(error="error",msg="message is already deleted for you")600 elif chk[0]==chk[1] or chk[0]==chk[2]:601 cur.execute("DELETE from message WHERE messageID = ?",(messageID,))602 msg = "message deleted for " + emailid603 return jsonify(msg=msg)604 con.commit()605 msg = "message deleted for " + emailid606 return jsonify(msg=msg)607 else:608 return jsonify(error="error",msg="Account is not registered with this emailId or invalid sessionid") 609 except:610 return jsonify(error="error",msg="Error in api request")611@app.route('/block', methods= ['GET', 'POST'])612def block():613 try:614 sessionid=request.values.get('sessionid')615 emailid=request.values.get('emailid')616 block=request.values.get('block')617 chk=isValidEmail(emailid) and isValidEmail(block) and isValidSession(sessionid)618 if chk==False:619 return jsonify(error="error",msg='invalid emailid or invalid recipient or sessionid')620 msg="failed"621 if emailid==block:622 return jsonify(error="error",msg="Cannot block yourself")623 with sqlite3.connect("Tinder.db") as con:624 cur = con.cursor()625 cur.execute("SELECT EmailID from Users where EmailID=?",(block,))626 chk=cur.fetchone()627 if chk==None:628 return jsonify(error="error",msg="recipient is not registered")629 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))630 chk = cur.fetchone()631 if chk==None:632 return jsonify(error="error",msg="Emailid not registered")633 if chk[0] == sessionid :634 cur.execute("SELECT block from Block where user=? and block=?",(emailid,block))635 chk=cur.fetchone()636 if chk is None:637 cur.execute("INSERT INTO Block (user,block) VALUES (?,?)",(emailid,block))638 return jsonify(msg="You have blocked the user")639 else:640 return jsonify(error="error",msg="You have already blocked the user")641 con.commit()642 else:643 return jsonify(error="error",msg="Account is not registered with this emailId or invalid sessionid") 644 except:645 return jsonify(error="error",msg="Error in api request")646@app.route('/unblock', methods= ['GET', 'POST'])647def unblock():648 try:649 sessionid=request.values.get('sessionid')650 emailid=request.values.get('emailid')651 unblock=request.values.get('unblock')652 chk=isValidEmail(emailid) and isValidEmail(unblock) and isValidSession(sessionid)653 if chk==False:654 return jsonify(error="error",msg='invalid emailid or invalid recipient or sessionid')655 msg="failed"656 if emailid==unblock:657 return jsonify(error="error",msg="Cannot block or unblock yourself")658 with sqlite3.connect("Tinder.db") as con:659 cur = con.cursor()660 cur.execute("SELECT EmailID from Users where EmailID=?",(unblock,))661 chk=cur.fetchone()662 if chk==None:663 return jsonify(error="error",msg="recipient is not registered")664 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))665 chk = cur.fetchone()666 if chk==None:667 return jsonify(error="error",msg="Emailid not registered")668 if chk[0] == sessionid :669 cur.execute("SELECT block from Block where user=? and block=?",(emailid,unblock))670 chk=cur.fetchone()671 if chk is not None:672 cur.execute("DELETE from Block WHERE user = ? and block=?",(emailid,unblock))673 return jsonify(msg="You have unblocked the user")674 else:675 return jsonify(error="error",msg="You have not blocked the user")676 con.commit()677 else:678 return jsonify(error="error",msg="Account is not registered with this emailId or invalid sessionid") 679 except:680 return jsonify(error="error",msg="Error in api request")681@app.route('/messageFetch', methods= ['GET', 'POST'])682def messageFetch():683 try:684 sessionid=request.values.get('sessionid')685 emailid=request.values.get('emailid')686 reciever=request.values.get('reciever')687 want=request.values.get('want')688 chk=isValidEmail(emailid) and isValidEmail(reciever) and isValidSession(sessionid)689 if chk==False:690 return jsonify(error="error",msg='invalid emailid or invalid recipient or sessionid')691 msg="failed"692 if emailid==reciever:693 return jsonify(error="error",msg="Cannot send message to yourself")694 with sqlite3.connect("Tinder.db") as con:695 cur = con.cursor()696 cur.execute("SELECT EmailID from Users where EmailID=?",(reciever,))697 chk=cur.fetchone()698 if chk==None:699 return jsonify(error="error",msg="recipient is not registered")700 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))701 chk = cur.fetchone()702 if chk==None:703 return jsonify(error="error",msg="Emailid not registered")704 if chk[0] == sessionid :705 cur.execute("SELECT * from Message where sender=? and recipient=?",(emailid,reciever))706 tm=cur.fetchall()707 cur.execute("SELECT * from Message where sender=? and recipient=?",(reciever,emailid))708 fm=cur.fetchall()709 mIDs=[]710 tmf=[]711 for i in tm:712 if i[4] in [emailid,reciever]:713 pass714 else:715 tmf.append(i)716 mIDs.append(i[5])717 fmf=[]718 for i in fm:719 if i[4] in [emailid,reciever]:720 pass721 else:722 fmf.append(i)723 mIDs.append(i[5])724 messages=tmf+fmf725 #print (messages)726 fmessages=[]727 mIDs.sort()728 print (mIDs)729 if want is None:730 pass731 else:732 l=len(mIDs)733 if l>want:734 return jsonify(error="error",msg="No of messages is less than what you requested")735 else:736 a=l-int(want)737 mIDs=mIDs[a:]738 print (mIDs)739 for i in mIDs:740 for j in messages:741 if j[5]==i:742 fmessages.append(j)743 con.commit()744 msg = "message list between " + emailid + " and " + reciever745 return jsonify(msg=msg,messages=fmessages)746 else:747 return jsonify(error="error",msg="Account is not registered with this emailId or invalid sessionid") 748 except:749 return jsonify(error="error",msg="Error in api request")750@app.route('/connected', methods= ['GET', 'POST'])751def connected():752 try:753 sessionid=request.values.get('sessionid')754 emailid=request.values.get('emailid')755 chk=isValidEmail(emailid) and isValidSession(sessionid)756 if chk==False:757 return jsonify(error="error",msg='invalid emailid or sessionid')758 msg="failed"759 with sqlite3.connect("Tinder.db") as con:760 cur = con.cursor()761 cur.execute("SELECT SessionID from Users where EmailID=?",(emailid,))762 chk = cur.fetchone()763 if chk == None:764 return jsonify(error="error",msg="Emailid is not registered")765 if chk[0] == sessionid :766 cur.execute("SELECT recipient from Message where sender=?",(emailid,))767 sent=cur.fetchall()768 cur.execute("SELECT sender from Message where recipient=?",(emailid,))769 recieved=cur.fetchall()770 connections=[]771 for i in sent:772 if i in connections:773 pass774 else:775 connections.append(i)776 for i in recieved:777 if i in connections:778 pass779 else:780 connections.append(i)781 return jsonify(usersList=connections)782 else:783 return jsonify(error="error",msg="Invalid sessionid") 784 except:785 msg = "Emailid not registered"786 return jsonify(error="error",msg=msg)787if __name__ == '__main__':...

Full Screen

Full Screen

member.py

Source:member.py Github

copy

Full Screen

...11def add_member(org_id: str):12 try:13 add_member_request = manager.AddMemberRequest(**request.json)14 response = manager.add_member(org_id, g.user_id, add_member_request)15 return jsonify(response)16 except ValidationError as e:17 current_app.logger.error('Issue with json body')18 return jsonify({"error": "Issue creating project", "code": 40016}), 40019 except DuplicateAddMemberException as ex:20 current_app.logger.error(f'Already member in list for email: {ex.email}. Please delete invite if not needed')21 return jsonify({"error": f'Already member in list for email: {ex.email}. Please delete invite if not needed',22 "code": 40017}), 40023 except UserNotFoundException as ex:24 current_app.logger.error(f'User not found for id: {ex.user_id}')25 return jsonify({"error": f'User not found for id: {ex.user_id}', "code": 40444}), 40426 except OrganisationNotFoundException as ex:27 current_app.logger.warn(f"Unknown organisation: {org_id}")28 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40445}), 40429 except DeletedOrganisationAccessException as ex:30 current_app.logger.warn(f"Access to deleted organisation: {org_id}")31 return jsonify({"error": "Accessing deleted organisations", "code": 40446}), 40432 except InsufficientOwnerAccessException as ex:33 current_app.logger.warn(f'Trying to add owner with insufficient permission: {ex.user_id}')34 return jsonify({"error": "Only an owner can add another owner", "code": 40114}), 40135 except OrganisationIllegalAccessException as ex:36 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")37 return jsonify({"error": "Not enough permissions to perform action", "code": 40115}), 40138 except UnknownSystemException as e:39 return jsonify({"error": "Unknown system exception", "code": 50014}), 50040@blueprint.route('', methods=['GET'])41def get_members(org_id: str):42 try:43 response = list(map(lambda member: member.dict(), manager.get_members(org_id, g.user_id)))44 return jsonify(response)45 except UserNotFoundException as ex:46 current_app.logger.error(f'User not found for id: {ex.user_id}')47 return jsonify({"error": f'User not found for id: {ex.user_id}', "code": 40447}), 40448 except OrganisationNotFoundException as ex:49 current_app.logger.warn(f"Unknown organisation: {org_id}")50 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40448}), 40451 except DeletedOrganisationAccessException as ex:52 current_app.logger.warn(f"Access to deleted organisation: {org_id}")53 return jsonify({"error": "Accessing deleted organisations", "code": 40449}), 40454 except OrganisationIllegalAccessException as ex:55 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")56 return jsonify({"error": "Not enough permissions to perform action", "code": 40116}), 40157 except UnknownSystemException as e:58 return jsonify({"error": "Unknown system exception", "code": 50015}), 50059@blueprint.route('/invites', methods=['GET'])60def get_invites(org_id: str):61 try:62 response = list(map(lambda invite: invite.dict(), manager.get_invites(org_id, g.user_id)))63 return jsonify(response)64 except UserNotFoundException as ex:65 current_app.logger.error(f'User not found for id: {ex.user_id}')66 return jsonify({"error": f'User not found for id: {ex.user_id}', "code": 40450}), 40467 except OrganisationNotFoundException as ex:68 current_app.logger.warn(f"Unknown organisation: {org_id}")69 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40451}), 40470 except DeletedOrganisationAccessException as ex:71 current_app.logger.warn(f"Access to deleted organisation: {org_id}")72 return jsonify({"error": "Accessing deleted organisations", "code": 40452}), 40473 except OrganisationIllegalAccessException as ex:74 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")75 return jsonify({"error": "Not enough permissions to perform action", "code": 40117}), 40176 except UnknownSystemException as e:77 return jsonify({"error": "Unknown system exception", "code": 50016}), 50078@blueprint.route('/<string:member_id>', methods=['PUT'])79def edit_member(org_id: str, member_id: str):80 try:81 edit_member_request = manager.EditMemberRequest(**request.json)82 response = manager.edit_member(org_id, g.user_id, member_id, edit_member_request)83 return jsonify(response.dict())84 except ValidationError as e:85 current_app.logger.error('Issue with json body')86 return jsonify({"error": "Issue creating project", "code": 40018}), 40087 except UserNotFoundException as ex:88 current_app.logger.error(f'User not found for id: {ex.user_id}')89 return jsonify({"error": f'User not found for id: {ex.user_id}', "code": 40453}), 40490 except OrganisationNotFoundException as ex:91 current_app.logger.warn(f"Unknown organisation: {org_id}")92 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40454}), 40493 except DeletedOrganisationAccessException as ex:94 current_app.logger.warn(f"Access to deleted organisation: {org_id}")95 return jsonify({"error": "Accessing deleted organisations", "code": 40455}), 40496 except UnknownMemberException as ex:97 current_app.logger.warn(f'Unknown member id: {ex.member_id}')98 return jsonify({"error": f"Unknown member id: {ex.member_id}", "code": 40456}), 40499 except InsufficientOwnerAccessException as ex:100 current_app.logger.warn(f'Trying to add owner with insufficient permission: {ex.user_id}')101 return jsonify({"error": "Only an owner can add another owner", "code": 40117}), 401102 except OrganisationIllegalAccessException as ex:103 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")104 return jsonify({"error": "Not enough permissions to perform action", "code": 40118}), 401105 except UnknownSystemException as e:106 return jsonify({"error": "Unknown system exception", "code": 50015}), 500107@blueprint.route('/invites/<string:invite_id>', methods=['PUT'])108def edit_invite(org_id: str, invite_id: str):109 try:110 edit_invite_request = manager.EditInviteRequest(**request.json)111 response = manager.edit_invite(org_id, g.user_id, invite_id, edit_invite_request)112 return jsonify(response.dict())113 except ValidationError as e:114 current_app.logger.error('Issue with json body')115 return jsonify({"error": "Issue creating project", "code": 40019}), 400116 except DuplicateAddMemberException as ex:117 current_app.logger.error(f'Already member in list for email: {ex.email}. Please delete invite if not needed')118 return jsonify({"error": f'Already member in list for email: {ex.email}. Please delete invite if not needed',119 "code": 40020}), 400120 except UserNotFoundException as ex:121 current_app.logger.error(f'User not found for id: {ex.user_id}')122 return jsonify({"error": f'User not found for id: {ex.user_id}', "code": 40456}), 404123 except OrganisationNotFoundException as ex:124 current_app.logger.warn(f"Unknown organisation: {org_id}")125 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40457}), 404126 except DeletedOrganisationAccessException as ex:127 current_app.logger.warn(f"Access to deleted organisation: {org_id}")128 return jsonify({"error": "Accessing deleted organisations", "code": 40458}), 404129 except UnknownInviteException as ex:130 return jsonify({"error": f"Unknown invite: {ex.invite_id}", "code": 40459}), 404131 except InsufficientOwnerAccessException as ex:132 current_app.logger.warn(f'Trying to add owner with insufficient permission: {ex.user_id}')133 return jsonify({"error": "Only an owner can add another owner", "code": 40119}), 401134 except OrganisationIllegalAccessException as ex:135 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")136 return jsonify({"error": "Not enough permissions to perform action", "code": 40120}), 401137 except UnknownSystemException as e:138 return jsonify({"error": "Unknown system exception", "code": 50016}), 500139@blueprint.route('/<string:member_id>', methods=['DELETE'])140def delete_member(org_id: str, member_id: str):141 try:142 response = manager.delete_member(org_id, g.user_id, member_id)143 return jsonify(response)144 except UserNotFoundException as ex:145 current_app.logger.error(f'User not found for id: {ex.user_id}')146 return jsonify({"error": f'User not found for id: {ex.user_id}', "code": 40460}), 404147 except OrganisationNotFoundException as ex:148 current_app.logger.warn(f"Unknown organisation: {org_id}")149 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40461}), 404150 except DeletedOrganisationAccessException as ex:151 current_app.logger.warn(f"Access to deleted organisation: {org_id}")152 return jsonify({"error": "Accessing deleted organisations", "code": 40462}), 404153 except UnknownMemberException as ex:154 current_app.logger.warn(f"unknown member id: {ex.member_id}")155 return jsonify({"error": f"Unknown member id: {ex.member_id}", "code": 40021}), 400156 except OrganisationIllegalAccessException as ex:157 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")158 return jsonify({"error": "Not enough permissions to perform action", "code": 40121}), 401159 except UnknownSystemException as e:160 return jsonify({"error": "Unknown system exception", "code": 50017}), 500161@blueprint.route('/invites/<string:invite_id>', methods=['DELETE'])162def delete_invite(org_id: str, invite_id: str):163 try:164 response = manager.delete_invite(org_id, g.user_id, invite_id)165 return jsonify(response)166 except UserNotFoundException as ex:167 current_app.logger.error(f'User not found for id: {ex.user_id}')168 return jsonify({"error": f'User not found for id: {ex.user_id}', "code": 40463}), 404169 except OrganisationNotFoundException as ex:170 current_app.logger.warn(f"Unknown organisation: {org_id}")171 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40464}), 404172 except DeletedOrganisationAccessException as ex:173 current_app.logger.warn(f"Access to deleted organisation: {org_id}")174 return jsonify({"error": "Accessing deleted organisations", "code": 40465}), 404175 except UnknownInviteException as ex:176 return jsonify({"error": f"Unknown invite: {ex.invite_id}", "code": 40466}), 404177 except InsufficientOwnerAccessException as ex:178 current_app.logger.warn(f'Trying to add owner with insufficient permission: {ex.user_id}')179 return jsonify({"error": "Only an owner can add another owner", "code": 40122}), 401180 except OrganisationIllegalAccessException as ex:181 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")182 return jsonify({"error": "Not enough permissions to perform action", "code": 40123}), 401183 except UnknownSystemException as e:184 return jsonify({"error": "Unknown system exception", "code": 50018}), 500185@blueprint.route('/<string:member_id>/enable', methods=['PUT'])186def enable_member(org_id: str, member_id: str):187 try:188 response = manager.enable_member(org_id, g.user_id, member_id)189 return jsonify(response.dict())190 except UserNotFoundException as ex:191 current_app.logger.error(f'User not found for id: {ex.user_id}')192 return jsonify({"error": f'User not found for id: {ex.user_id}', "code": 40467}), 404193 except OrganisationNotFoundException as ex:194 current_app.logger.warn(f"Unknown organisation: {org_id}")195 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40468}), 404196 except DeletedOrganisationAccessException as ex:197 current_app.logger.warn(f"Access to deleted organisation: {org_id}")198 return jsonify({"error": "Accessing deleted organisations", "code": 40469}), 404199 except UnknownMemberException as ex:200 current_app.logger.warn(f"unknown member id: {ex.member_id}")201 return jsonify({"error": f"Unknown member id: {ex.member_id}", "code": 40022}), 400202 except OrganisationIllegalAccessException as ex:203 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")204 return jsonify({"error": "Not enough permissions to perform action", "code": 40124}), 401205 except UnknownSystemException as e:206 return jsonify({"error": "Unknown system exception", "code": 50019}), 500207@blueprint.route('/invites/<string:invite_id>/enable', methods=['PUT'])208def enable_invite(org_id: str, invite_id: str):209 try:210 response = manager.enable_invite(org_id, g.user_id, invite_id)211 return jsonify(response.dict())212 except DuplicateAddMemberException as ex:213 current_app.logger.error(f'Already member in list for email: {ex.email}. Please delete invite if not needed')214 return jsonify({"error": f'Already member in list for email: {ex.email}. Please delete invite if not needed',215 "code": 40023}), 400216 except UserNotFoundException as ex:217 current_app.logger.error(f'User not found for id: {ex.user_id}')218 return jsonify({"error": f'User not found for id: {ex.user_id}', "code": 40470}), 404219 except OrganisationNotFoundException as ex:220 current_app.logger.warn(f"Unknown organisation: {org_id}")221 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40471}), 404222 except DeletedOrganisationAccessException as ex:223 current_app.logger.warn(f"Access to deleted organisation: {org_id}")224 return jsonify({"error": "Accessing deleted organisations", "code": 40472}), 404225 except UnknownInviteException as ex:226 return jsonify({"error": f"Unknown invite: {ex.invite_id}", "code": 40473}), 404227 except InsufficientOwnerAccessException as ex:228 current_app.logger.warn(f'Trying to add owner with insufficient permission: {ex.user_id}')229 return jsonify({"error": "Only an owner can add another owner", "code": 40125}), 401230 except OrganisationIllegalAccessException as ex:231 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")232 return jsonify({"error": "Not enough permissions to perform action", "code": 40126}), 401233 except UnknownSystemException as e:...

Full Screen

Full Screen

project.py

Source:project.py Github

copy

Full Screen

...10def create_project(org_id: str):11 try:12 create_project_request = manager.ProjectRequest(**request.json)13 create_project_response = manager.create_project(org_id, g.user_id, create_project_request)14 return jsonify(create_project_response.dict())15 except ValidationError as e:16 current_app.logger.error('Issue with json body')17 return jsonify({"error": "Issue creating project", "code": 40007}), 40018 except OrganisationNotFoundException as ex:19 current_app.logger.warn(f"Unknown organisation: {org_id}")20 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40407}), 40421 except DuplicateProjectNameException as e:22 current_app.logger.error('Duplicate name for project')23 return jsonify({"error": f"Duplicate name for project: {e.name}", "code": 40008}), 40024 except DeletedOrganisationAccessException as ex:25 current_app.logger.warn(f"Access to deleted organisation: {org_id}")26 return jsonify({"error": "Accessing deleted organisations", "code": 40408}), 40427 except OrganisationIllegalAccessException as ex:28 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")29 return jsonify({"error": "No access to organisation", "code": 40104}), 40130@blueprint.route('', methods=['GET'])31def get_projects(org_id: str):32 try:33 projects = manager.get_projects(org_id, g.user_id)34 projects_dict = list(map(lambda p: p.dict(), projects))35 return jsonify(projects_dict)36 except OrganisationNotFoundException as ex:37 current_app.logger.warn(f"Unknown organisation: {org_id}")38 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40409}), 40439 except DeletedOrganisationAccessException as ex:40 current_app.logger.warn(f"Access to deleted organisation: {org_id}")41 return jsonify({"error": "Accessing deleted organisations", "code": 40410}), 40442 except OrganisationIllegalAccessException as ex:43 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")44 return jsonify({"error": "No access to organisation", "code": 40105}), 40145 except UnknownSystemException as ex:46 current_app.logger.error("Unknown system exception")47 return jsonify({"error": "Unknown system exception", "code": 50007}), 50048@blueprint.route('/<string:proj_id>', methods=["GET"])49def get_project(org_id: str, proj_id: str):50 try:51 project = manager.get_project(org_id, g.user_id, proj_id)52 return jsonify(project.dict())53 except OrganisationNotFoundException as ex:54 current_app.logger.warn(f"Unknown organisation: {org_id}")55 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40411}), 40456 except DeletedOrganisationAccessException as ex:57 current_app.logger.warn(f"Access to deleted organisation: {org_id}")58 return jsonify({"error": "Accessing deleted organisations", "code": 40412}), 40459 except OrganisationIllegalAccessException as ex:60 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")61 return jsonify({"error": "No access to organisation", "code": 40106}), 40162 except ProjectNotFoundException as ex:63 current_app.logger.warn(f"Unknown project: {ex.proj_id}")64 return jsonify({"error": f"Unknown project by id {ex.proj_id}", "code": 40410}), 40465@blueprint.route('/<string:proj_id>', methods=['PUT'])66def edit_project(org_id: str, proj_id: str):67 try:68 edit_project_request = manager.ProjectModel(**request.json)69 project = manager.edit_project(org_id, g.user_id, proj_id, edit_project_request)70 return jsonify(project.dict())71 except ValidationError as e:72 current_app.logger.error('Issue with json body')73 return jsonify({"error": "Issue creating project", "code": 40008}), 40074 except OrganisationNotFoundException as ex:75 current_app.logger.warn(f"Unknown organisation: {org_id}")76 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40413}), 40477 except DeletedOrganisationAccessException as ex:78 current_app.logger.warn(f"Access to deleted organisation: {org_id}")79 return jsonify({"error": "Accessing deleted organisations", "code": 40414}), 40480 except OrganisationIllegalAccessException as ex:81 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")82 return jsonify({"error": "No access to organisation", "code": 40107}), 40183 except ProjectNotFoundException as ex:84 current_app.logger.warn(f"Unknown project: {ex.proj_id}")85 return jsonify({"error": f"Unknown project by id {ex.proj_id}", "code": 40415}), 40486 except UnknownSystemException as ex:87 current_app.logger.error("Unknown system exception")88 return jsonify({"error": "Unknown system exception", "code": 50008}), 50089@blueprint.route('/<string:proj_id>', methods=['DELETE'])90def delete_project(org_id: str, proj_id: str):91 try:92 delete_project_response = manager.delete_project(org_id, g.user_id, proj_id)93 return jsonify(delete_project_response)94 except OrganisationNotFoundException as ex:95 current_app.logger.warn(f"Unknown organisation: {org_id}")96 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40416}), 40497 except DeletedOrganisationAccessException as ex:98 current_app.logger.warn(f"Access to deleted organisation: {org_id}")99 return jsonify({"error": "Accessing deleted organisations", "code": 40417}), 404100 except ProjectNotFoundException as ex:101 current_app.logger.warn(f"Unknown project: {ex.proj_id}")102 return jsonify({"error": f"Unknown project by id {ex.proj_id}", "code": 40418}), 404103 except OrganisationIllegalAccessException as ex:104 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")105 return jsonify({"error": "No access to organisation", "code": 40108}), 401106 except UnknownSystemException as e:107 return jsonify({"error": "Unknown system exceptions", "code": 50009}), 500108@blueprint.route('/<string:proj_id>/keys', methods=['POST'])109def create_key(org_id: str, proj_id: str):110 try:111 create_key_response = manager.create_key(org_id, g.user_id, proj_id, manager.KeyRequest(**request.json))112 return create_key_response.dict()113 except OrganisationNotFoundException as ex:114 current_app.logger.warn(f"Unknown organisation: {org_id}")115 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40419}), 404116 except DeletedOrganisationAccessException as ex:117 current_app.logger.warn(f"Access to deleted organisation: {org_id}")118 return jsonify({"error": "Accessing deleted organisations", "code": 40420}), 404119 except ProjectNotFoundException as ex:120 current_app.logger.warn(f"Unknown project: {ex.proj_id}")121 return jsonify({"error": f"Unknown project by id {ex.proj_id}", "code": 40421}), 404122 except OrganisationIllegalAccessException as ex:123 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")124 return jsonify({"error": "No access to organisation", "code": 40109}), 401125 except DuplicateKeyNameException as ex:126 return jsonify({"error": f"Duplicate key name in project {ex.name}", "code": 40009}), 400127 except DuplicateKeyException as ex:128 current_app.logger.error(f"This should really not happen. big trouble. duplicate key: {ex.key}")129 return jsonify({"error": "Duplicate key", "code": 50010}), 500130 except UnknownSystemException as e:131 return jsonify({"error": "Unknown system exceptions", "code": 50011}), 500132@blueprint.route('/<string:proj_id>/keys', methods=['GET'])133def get_keys(org_id: str, proj_id: str):134 try:135 get_keys_response = manager.get_keys(org_id, g.user_id, proj_id)136 response = list(map(lambda key: key.dict(), get_keys_response))137 return jsonify(response)138 except OrganisationNotFoundException as ex:139 current_app.logger.warn(f"Unknown organisation: {org_id}")140 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40422}), 404141 except DeletedOrganisationAccessException as ex:142 current_app.logger.warn(f"Access to deleted organisation: {org_id}")143 return jsonify({"error": "Accessing deleted organisations", "code": 40423}), 404144 except ProjectNotFoundException as ex:145 current_app.logger.warn(f"Unknown project: {ex.proj_id}")146 return jsonify({"error": f"Unknown project by id {ex.proj_id}", "code": 40424}), 404147 except OrganisationIllegalAccessException as ex:148 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")149 return jsonify({"error": "No access to organisation", "code": 40110}), 401150 except UnknownSystemException as e:151 return jsonify({"error": "Unknown system exceptions", "code": 50012}), 500152@blueprint.route('/<string:proj_id>/keys/<string:key_id>', methods=['GET'])153def get_key(org_id: str, proj_id: str, key_id: str):154 try:155 response = manager.get_key(org_id, g.user_id, proj_id, key_id)156 return jsonify(response.dict())157 except OrganisationNotFoundException as ex:158 current_app.logger.warn(f"Unknown organisation: {org_id}")159 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40425}), 404160 except DeletedOrganisationAccessException as ex:161 current_app.logger.warn(f"Access to deleted organisation: {org_id}")162 return jsonify({"error": "Accessing deleted organisations", "code": 40426}), 404163 except ProjectNotFoundException as ex:164 current_app.logger.warn(f"Unknown project: {ex.proj_id}")165 return jsonify({"error": f"Unknown project by id {ex.proj_id}", "code": 40427}), 404166 except DeletedKeyAccessException as ex:167 current_app.logger.warn(f"Accessing deleted key: {ex.key_id}")168 return jsonify({"error": f"Accessing deleted key by id {ex.key_id}", "code": 40428}), 404169 except KeyNotFoundException as ex:170 current_app.logger.warn(f'Unknown key: {ex.key_id}')171 return jsonify({"error": f"Unknown key by id {ex.key_id}", "code": 40429}), 404172 except OrganisationIllegalAccessException as ex:173 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")174 return jsonify({"error": "No access to organisation", "code": 40111}), 401175 except UnknownSystemException as e:176 return jsonify({"error": "Unknown system exceptions", "code": 50013}), 500177@blueprint.route('/<string:proj_id>/keys/<string:key_id>', methods=['PUT'])178def edit_key(org_id: str, proj_id: str, key_id: str):179 try:180 edit_key_request = manager.KeyRequest(**request.json)181 edit_key_response = manager.edit_key(org_id, g.user_id, proj_id, key_id, edit_key_request)182 return edit_key_response.dict()183 except OrganisationNotFoundException as ex:184 current_app.logger.warn(f"Unknown organisation: {org_id}")185 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40430}), 404186 except DeletedOrganisationAccessException as ex:187 current_app.logger.warn(f"Access to deleted organisation: {org_id}")188 return jsonify({"error": "Accessing deleted organisations", "code": 40431}), 404189 except ProjectNotFoundException as ex:190 current_app.logger.warn(f"Unknown project: {ex.proj_id}")191 return jsonify({"error": f"Unknown project by id {ex.proj_id}", "code": 40432}), 404192 except DeletedKeyAccessException as ex:193 return jsonify({"error": f"Key has been deleted {ex.key_id}", "code": 40433}), 404194 except OrganisationIllegalAccessException as ex:195 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")196 return jsonify({"error": "No access to organisation", "code": 40112}), 401197 except DuplicateKeyNameException as ex:198 return jsonify({"error": f"Duplicate key name in project {ex.name}", "code": 40010}), 400199 except UnknownSystemException as e:200 return jsonify({"error": "Unknown system exceptions", "code": 50012}), 500201@blueprint.route('/<string:proj_id>/keys/<string:key_id>', methods=['DELETE'])202def delete_key(org_id: str, proj_id: str, key_id: str):203 try:204 delete_response = manager.delete_key(org_id, g.user_id, proj_id, key_id)205 return jsonify(delete_response)206 except OrganisationNotFoundException as ex:207 current_app.logger.warn(f"Unknown organisation: {org_id}")208 return jsonify({"error": f"Unknown organisation by id: {org_id}", "code": 40434}), 404209 except DeletedOrganisationAccessException as ex:210 current_app.logger.warn(f"Access to deleted organisation: {org_id}")211 return jsonify({"error": "Accessing deleted organisations", "code": 40435}), 404212 except ProjectNotFoundException as ex:213 current_app.logger.warn(f"Unknown project: {ex.proj_id}")214 return jsonify({"error": f"Unknown project by id {ex.proj_id}", "code": 40436}), 404215 except KeyNotFoundException as ex:216 current_app.logger.warn(f"Unknown key: {ex.key_id}")217 return jsonify({"error": f"Unknown key by id {ex.key_id}", "code": 40437}), 404218 except DeletedKeyAccessException as ex:219 return jsonify({"error": f"Key already deleted {ex.key_id}", "code": 40438}), 404220 except OrganisationIllegalAccessException as ex:221 current_app.logger.warn(f"Unauthorized access: {org_id} by {g.user_id}")222 return jsonify({"error": "No access to organisation", "code": 40113}), 401223 except UnknownSystemException as e:...

Full Screen

Full Screen

backend.py

Source:backend.py Github

copy

Full Screen

...76 data_n = imp.transform(data)77 model = p.load(open("./model/kmodel.pkl","rb"))78 pred = model.predict(data_n)[0]79 print(pred)80 return jsonify(str(pred), prob)81@app.route("/add_details", methods=['POST'])82def add_details():83 fname = request.json['filename']84 data = pd.read_csv(fname)85 master = pd.read_csv("master.csv")86 master = master.append(data, ignore_index=True)87 master.to_csv("master.csv", index=None)88@app.route("/view_details", methods=['POST'])89def view_details():90 recordID = request.json['recordID']91 master = pd.read_csv("master.csv")92 data = master[master['Patient_Id']==int(recordID)]93 return jsonify(data.transpose().to_html(classes='table table-striped" id= "a_nice_table', border=0, header=None, bold_rows=True))94def distance(lat1, lon1, lat2, lon2):95 p = 0.01745329251994329596 a = 0.5 - cos((lat2-lat1)*p)/2 + cos(lat1*p)*cos(lat2*p) * (1-cos((lon2-lon1)*p)) / 297 return 12742 * asin(sqrt(a))98def closest(data, v):99 return min(data, key=lambda p: distance(v['lat'],v['lon'],p['LAT'],p['LON']))100@app.route("/view_details_aller", methods=['POST'])101def view_details_aller():102 recordID = request.json['recordID']103 latID = request.json['latID']104 lonID = request.json['lonID']105 allermed = p.load(open("./model/allermed.pickle","rb"))106 med = allermed[recordID][0][0] + ", " + allermed[recordID][1][0] + ", "+allermed[recordID][2][0]107 address = "Not Available"108 if len(latID) == 0 or len(lonID) == 0:109 return jsonify(med, address) 110 allerorg = p.load(open("./model/allerorg.pickle","rb"))111 nearorg = closest(allerorg[recordID], {'lat':float(latID), 'lon':float(lonID)})112 address = nearorg.iloc[0]['NAME'] + ", " + nearorg.iloc[0]['ADDRESS'] + ", CITY-"+ nearorg.iloc[0]['CITY'] + ", Zip -"+ nearorg.iloc[0]['ZIP'] + ", Phone NO.-"+nearorg.iloc[0]['PHONE']113 #print(str(address))114 return jsonify(med, address)115@app.route("/view_height_details", methods=['POST'])116def view_height_details():117 recordID = request.json['recordID']118 if len(recordID) == 0:119 return jsonify("Height can't be None")120 sexID = request.json['sexID']121 if sexID != 'M' and sexID != 'F':122 return jsonify("Sex should be 'M' or 'F'")123 height = 30.48*float(recordID)124 if height <= 49.3:125 return jsonify("around 3.3 kg")126 elif height <=54.8:127 return jsonify("around 4.4 kg")128 elif height <=58.4:129 return jsonify("around 5.6 kg")130 elif height <=61.4:131 return jsonify("around 6.4 kg")132 elif height <=64:133 return jsonify("around 7 kg")134 elif height <=66:135 return jsonify("around 7.5 kg")136 elif height <=67.5:137 return jsonify("around 7.9 kg")138 elif height <=69:139 return jsonify("around 8.3 kg")140 elif height <=70.6:141 return jsonify("around 8.6 kg")142 elif height <=71.8:143 return jsonify("around 8.9 kg")144 elif height <=73.1:145 return jsonify("around 9.1 kg")146 elif height <=74.4:147 return jsonify("around 9.4 kg")148 elif height <=75.7:149 return jsonify("around 9.6 kg")150 elif height <=76.9:151 return jsonify("around 10.1 kg")152 elif height <=80.2:153 return jsonify("around 10.5 kg")154 elif height <=85:155 return jsonify("around 11.5 kg")156 elif height <=86.8:157 return jsonify("around 11.9 kg")158 elif height <=95.2:159 return jsonify("around 14 kg")160 elif height <=110:161 return jsonify("around 18.4 kg")162 elif height <=115.5:163 return jsonify("around 20.6 kg")164 elif height <=121:165 return jsonify("around 22.9 kg")166 elif height <=133:167 return jsonify("around 28.5 kg")168 else:169 if sexID == 'M':170 if(height <=137):171 return jsonify("28.5-34.9 kg")172 elif(height <= 140):173 return jsonify("30.8-38.1 kg")174 elif(height <= 142):175 return jsonify("33.5-40.8 kg")176 elif(height <= 145):177 return jsonify("35.8-43.9 kg")178 elif(height <= 147):179 return jsonify("38.5-46.7 kg")180 elif(height <= 150):181 return jsonify("40.8-49.9 kg")182 elif(height <= 152):183 return jsonify("43.1-53 kg")184 elif(height <= 155):185 return jsonify("45.8-55.8 kg")186 elif(height <= 157):187 return jsonify("48.1-58.9 kg")188 elif(height <= 160):189 return jsonify("50.8-61.6 kg")190 elif(height <= 163):191 return jsonify("53-64.8 kg")192 elif(height <= 165):193 return jsonify("55.3-68 kg")194 elif(height <= 168):195 return jsonify("58-70.7 kg")196 elif(height <= 170):197 return jsonify("60.3-73.9 kg")198 elif(height <= 173):199 return jsonify("63-76.6 kg")200 elif(height <= 175):201 return jsonify("65.3-79.8 kg")202 elif(height <= 178):203 return jsonify("67.6-83 kg")204 elif(height <= 180):205 return jsonify("70.3-85.7 kg")206 elif(height <= 183):207 return jsonify("72.6-88.9 kg")208 elif(height <= 185):209 return jsonify("75.3-91.6 kg")210 elif(height <= 188):211 return jsonify("77.5-94.8 kg")212 elif(height <= 191):213 return jsonify("79.9-98 kg")214 elif(height <= 193):215 return jsonify("82.5-100.6 kg")216 elif(height <= 195):217 return jsonify("84.8-103.8 kg")218 elif(height <= 198):219 return jsonify("87.5-106.5 kg")220 elif(height <= 201):221 return jsonify("89.8-109.7 kg")222 elif(height <= 203):223 return jsonify("93-112.9 kg")224 elif(height <= 205):225 return jsonify("94.8-115.6 kg")226 elif(height <= 208):227 return jsonify("97-118.8 kg")228 elif(height <= 210):229 return jsonify("99.8-121.5 kg")230 elif(height <= 213):231 return jsonify("102-124.7 kg")232 else:233 return jsonify("No data available")234 else:235 if(height <=137):236 return jsonify("28.5-34.9 kg")237 elif(height <= 140):238 return jsonify("30.8-37.6 kg")239 elif(height <= 142):240 return jsonify("32.6-39.9 kg")241 elif(height <= 145):242 return jsonify("34.9-42.6 kg")243 elif(height <= 147):244 return jsonify("36.4-44.9 kg")245 elif(height <= 150):246 return jsonify("39-47.6 kg")247 elif(height <= 152):248 return jsonify("40.8-49.9 kg")249 elif(height <= 155):250 return jsonify("43.1-52.6 kg")251 elif(height <= 157):252 return jsonify("44.9-54.9 kg")253 elif(height <= 160):254 return jsonify("47.2-57.6 kg")255 elif(height <= 163):256 return jsonify("49-59.9 kg")257 elif(height <= 165):258 return jsonify("51.2-62.6 kg")259 elif(height <= 168):260 return jsonify("53-64.8 kg")261 elif(height <= 170):262 return jsonify("55.3-67.6 kg")263 elif(height <= 173):264 return jsonify("57.1-69.8 kg")265 elif(height <= 175):266 return jsonify("59.4-72.6 kg")267 elif(height <= 178):268 return jsonify("61.2-74.8 kg")269 elif(height <= 180):270 return jsonify("63.5-77.5 kg")271 elif(height <= 183):272 return jsonify("65.3-79.8 kg")273 elif(height <= 185):274 return jsonify("67.6-82.5 kg")275 elif(height <= 188):276 return jsonify("69.4-84.8 kg")277 elif(height <= 191):278 return jsonify("71.6-87.5 kg")279 elif(height <= 193):280 return jsonify("73.5-89.8 kg")281 elif(height <= 195):282 return jsonify("75.7-92.5 kg")283 elif(height <= 198):284 return jsonify("77.5-94.8 kg")285 elif(height <= 201):286 return jsonify("79.8-97.5 kg")287 elif(height <= 203):288 return jsonify("81.6-99.8 kg")289 elif(height <= 205):290 return jsonify("83.9-102.5 kg")291 elif(height <= 208):292 return jsonify("85.7-104.8 kg")293 elif(height <= 210):294 return jsonify("88-107.5 kg")295 elif(height <= 213):296 return jsonify("89.8-109.7 kg")297 else:298 return jsonify("No data available")299 300 if sexID == 'M':301 return jsonify("sahi male")302 elif sexID == 'F':303 return jsonify("sahi female")304 else:305 return jsonify("Sex should be 'M' or 'F'")306if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful