-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
58 lines (47 loc) · 1.58 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from flask import Flask, jsonify, request
import requests
from flask_swagger_ui import get_swaggerui_blueprint
from apis import comics
from apis import test
from apis import memes
from apis import nobel
from apis import blogs
from apis import gsoc
from apis import tv_shows
# Initialize the app
app = Flask(__name__, instance_relative_config=True)
# Load the config file
app.config.from_object('config')
SWAGGER_URL = '/swagger'
API_URL = '/static/swagger.json'
SWAGGERUI_BLUEPRINT = get_swaggerui_blueprint(
SWAGGER_URL,
API_URL,
config={
'app_name': "APIs"
}
)
app.register_blueprint(SWAGGERUI_BLUEPRINT, url_prefix=SWAGGER_URL)
# import apis and assigning url_prefix in lexographical order
app.register_blueprint(blogs, url_prefix='/api/blogs')
app.register_blueprint(comics, url_prefix='/api/comics')
app.register_blueprint(gsoc, url_prefix='/api/gsoc')
app.register_blueprint(nobel, url_prefix='/api/nobel')
app.register_blueprint(test, url_prefix='/api/test')
app.register_blueprint(memes, url_prefix='/api/memes')
app.register_blueprint(tv_shows, url_prefix='/api/tv_shows')
@app.route('/api')
def api():
endpoints = ['blogs', 'comics', 'gsoc',
'memes', 'nobel', 'test', 'tv_shows']
docs = []
url = request.url_root
for endpoint in endpoints:
data = requests.get('{}api/{}/docs'.format(url, endpoint)).json()
docs.extend(data['endpoints'])
return jsonify({'docs': docs})
@app.errorhandler(404)
def error(e):
return "Use the /api endpoint to get documentation about all the APIs"
if __name__ == "__main__":
app.run()