-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.py
39 lines (33 loc) · 897 Bytes
/
main.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
from goodreads import GoodReads
api = Flask(__name__)
@api.route('/')
def index():
res = {
'status': 200,
'about': 'Quotes api by W4RR10R',
'usage': [
'/random',
'/search/query/no of pages'
]
}
return jsonify(res)
@api.route('/random')
def random_quotes():
return jsonify(GoodReads().random)
@api.route('/search')
def search():
res = {
"error": {
'status': 400,
'detail': 'No search query found'
}
}
return jsonify(res)
@api.route('/search/<query>', defaults= {"pages": 1})
@api.route('/search/<query>/<pages>')
def search_quotes(query, pages):
results = GoodReads.search_all(query, int(pages))
return jsonify(results)
if __name__ == '__main__':
api.run(host="0.0.0.0", port=5000, debug=True)