Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. @app.route('/get_user_profile', methods=['POST'])
  2. def get_user_profile():
  3. try:
  4.  
  5. email = request.form['email']
  6. conn = MySQLdb.connect(host='localhost', user='muscle', password='some_pass')
  7. c = conn.cursor(MySQLdb.cursors.DictCursor)
  8. c.execute('USE muscle2')
  9.  
  10. c.execute("""SELECT Email, Name, Height, Weight, Profile_image, Plan FROM USER WHERE Email = %s""", [email])
  11.  
  12. fetched = c.fetchone()
  13.  
  14. img_dir = "user_profile_pics/"
  15. img_path = fetched['Profile_image']
  16.  
  17. string_img = None
  18.  
  19. if img_path != None and os.path.isfile(img_dir + img_path):
  20. with open(img_dir + img_path, "rb") as image_file:
  21. string_img = base64.b64encode(image_file.read()).decode()
  22.  
  23.  
  24. fetched['Profile_image'] = string_img
  25.  
  26. c.close()
  27. conn.close()
  28.  
  29. return jsonify(fetched)
  30.  
  31.  
  32. except Exception as e:
  33. return str(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement