-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
executable file
·39 lines (31 loc) · 1.12 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from flask import Flask, jsonify, render_template, abort
from qusasat import Qusasat
app = Flask(__name__)
qusasat = Qusasat(categories_file='./data/categories.csv', quotes_file='./data/qusasat.csv')
@app.route('/')
def root_html():
quote = qusasat.get_random_quote()
return render_template('quote.html',
category=quote['category'],
quote=quote['quote'],
background_image_url='/static/paper.png')
@app.route('/.json')
def root_json():
quote = qusasat.get_random_quote()
return jsonify(quote)
@app.route('/<int:quote_id>')
def get_quote_html(quote_id):
quote = qusasat.get_quote(str(quote_id))
if quote is None:
return abort(404)
else:
return render_template('quote.html', category=quote['category'], quote=quote['quote'])
@app.route('/<int:quote_id>.json')
def get_quote_json(quote_id):
quote = qusasat.get_quote(str(quote_id))
if quote is None:
return jsonify({'status': 'Not Found'}), 404
else:
return jsonify(quote)
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')