Advertisement
Guest User

Untitled

a guest
May 21st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. from flask import Flask
  2. import pyodbc
  3. app = Flask(__name__)
  4.  
  5. def connect():
  6. cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATABASE=testdb;UID=me;PWD=pass')
  7.     return cnxn.cursor()
  8.  
  9. cursor = connect()
  10.  
  11. @app.route('/ali_request_user')
  12. def get_user_id():
  13. cursor.execute("select user_id, user_name from users")
  14. rows = cursor.fetchall()
  15.     return rows
  16.  
  17. @app.route('/ali_request_image')
  18. def getEloScore(image):
  19. cursor.execute("""
  20. SELECT [EloScore]
  21. FROM [dbo].[Elo]
  22. WHERE [ImagePath] = ?
  23. """, image)
  24.  
  25.     return cursor.fetchone()
  26.  
  27. @app.route('/ali_request_votes')
  28. def getVotes(username):
  29. cursor.execute("""
  30. SELECT [ImagePath1]
  31. ,[ImagePath2]
  32. FROM [dbo].[Vote]
  33. WHERE [Username] = ?
  34. """, username)
  35.  
  36.     return cursor.fetchall()
  37.  
  38. if __name__ == '__main__':
  39.     app.run(host='0.0.0.0', port=5123)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement