Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. from flask import Flask,render_template,jsonify
  2. import time
  3. import pymysql.cursors
  4.  
  5. connection = pymysql.connect(host='localhost',
  6.                              user='REMOVED',
  7.                              password='REMOVED',
  8.                              db='REMOVED',
  9.                              charset='utf8mb4',
  10.                              cursorclass=pymysql.cursors.DictCursor)
  11.  
  12. app = Flask(__name__)
  13.  
  14. @app.route('/')
  15. def homepage():
  16.     return render_template('index.html')
  17.  
  18. @app.route('/api/recent/<time>')
  19. def api(time):
  20.     with connection.cursor() as cursor:
  21.         try:
  22.             time = float(time)
  23.             sql = "SELECT * FROM `chat` WHERE `response` IS NOT NULL AND `unix`> %s ORDER BY `unix` DESC LIMIT 25"
  24.             cursor.execute(sql,(time))
  25.             result = cursor.fetchall()
  26.         except Exception as e:
  27.             return 'What are you trying to do good sir?'
  28.        
  29.     return jsonify(result)
  30.  
  31.  
  32. if __name__ == "__main__":
  33.     app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement