Advertisement
Guest User

Untitled

a guest
May 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 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. def getVotes(username):
  28. cursor.execute("""
  29. SELECT [ImagePath1]
  30. ,[ImagePath2]
  31. FROM [dbo].[Vote]
  32. WHERE [Username] = ?
  33. """, username)
  34.  
  35. return cursor.fetchall()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement