Guest User

Untitled

a guest
Dec 8th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import mysql.connector as conn
  2. from flask import (
  3. render_template,
  4. Flask,
  5. jsonify,
  6. request,
  7. abort as ab
  8. )
  9.  
  10. app = Flask(__name__, template_folder='C:\Users\thomp\PycharmProjects\com661_1819_team_30\source\template\')
  11.  
  12. # Credentials here in code
  13. WHO = '*********'
  14. PWD = '********'
  15. DATABASE = '********'
  16.  
  17.  
  18. def conn_db():
  19. return conn.connect(user=WHO,
  20. password=PWD,
  21. host='**********',
  22. database=DATABASE
  23. )
  24.  
  25.  
  26. @app.route('/')
  27. def index():
  28. return render_template('scores.html')
  29.  
  30.  
  31.  
  32. @app.route('/addScore', methods=['POST'])
  33. def add_score():
  34. cnx = conn_db()
  35. cursor = cnx.cursor()
  36. MatchID = request.form['matchID']
  37. Home_Score = request.form['homeScore']
  38. Away_Score = request.form['awayScore']
  39.  
  40. print("Updating score")
  41. if not request.json:
  42. ab(400)
  43.  
  44. insert_score = "INSERT INTO scores (Match_ID, Home_Score, Away_Score) VALUES (%s,%s,%s)"
  45. cursor.execute(insert_score, (MatchID, Home_Score, Away_Score))
  46.  
  47.  
  48.  
  49. if __name__ == '__main__':
  50. app.run(debug=True, host='0.0.0.0')
Add Comment
Please, Sign In to add comment