-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
49 lines (39 loc) · 997 Bytes
/
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
#!/usr/bin/env python
"""
mascot: a microservice for serving mascot data
"""
import json
from flask import Flask, jsonify, abort, make_response
APP = Flask(__name__)
# Load the data
MASCOTS = json.load(open('data.json', 'r'))
@APP.route('/', methods=['GET'])
def get_mascots():
"""
Function: get_mascots
Input: none
Returns: A list of mascot objects
"""
return jsonify(MASCOTS)
@APP.route('/<guid>', methods=['GET'])
def get_mascot(guid):
"""
Function: get_mascot
Input: a mascot GUID
Returns: The mascot object with GUID matching the input
"""
for mascot in MASCOTS:
if guid == mascot['guid']:
return jsonify(mascot)
abort(404)
return None
@APP.errorhandler(404)
def not_found(error):
"""
Function: not_found
Input: The error
Returns: HTTP 404 with r
"""
return make_response(jsonify({'error': str(error)}), 404)
if __name__ == '__main__':
APP.run("0.0.0.0", port=8080, debug=True)