Advertisement
Guest User

Untitled

a guest
May 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. from flask import Flask
  2.  
  3. import pyodbc
  4.  
  5. app = Flask(__name__)
  6.  
  7.  
  8.  
  9. def connect():
  10.  
  11. cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATABASE=testdb;UID=me;PWD=pass')
  12.  
  13. return cnxn.cursor()
  14.  
  15.  
  16.  
  17. cursor = connect()
  18.  
  19.  
  20.  
  21. @app.route('/ali_request_user')
  22.  
  23. def get_user_id():
  24.  
  25. cursor.execute("select user_id, user_name from users")
  26.  
  27. rows = cursor.fetchall()
  28.  
  29. return rows
  30.  
  31.  
  32.  
  33. @app.route('/ali_request_image')
  34.  
  35. def getEloScore(image):
  36.  
  37. cursor.execute("""
  38.  
  39. SELECT [EloScore]
  40.  
  41. FROM [dbo].[Elo]
  42.  
  43. WHERE [ImagePath] = ?
  44.  
  45. """, image)
  46.  
  47.  
  48.  
  49. return cursor.fetchone()
  50.  
  51.  
  52.  
  53. def getVotes(username):
  54.  
  55. cursor.execute("""
  56.  
  57. SELECT [ImagePath1]
  58.  
  59. ,[ImagePath2]
  60.  
  61. FROM [dbo].[Vote]
  62.  
  63. WHERE [Username] = ?
  64.  
  65. """, username)
  66.  
  67.  
  68.  
  69. return cursor.fetchall()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement