-
Notifications
You must be signed in to change notification settings - Fork 3
/
api.py
35 lines (29 loc) · 1.1 KB
/
api.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
from flask import Flask, jsonify, abort, request
from config import API_HOST, API_PORT, NETWORKS, SCHEMA
from db import get_network_api_data, get_validator_api_data
app = Flask(__name__)
@app.route('/bro_score', methods=['GET'])
def get_network():
network = request.args.get('network', default='bostrom', type=str)
validator = request.args.get('validator', default=None, type=str)
limit = request.args.get('limit', default=-1, type=int)
if not validator:
network_data = get_network_api_data(network, limit)
return jsonify({
"schema": SCHEMA,
"result": network_data[1],
"last_update": network_data[0]
})
elif not network and not validator:
abort(404)
elif not network or network not in [n['name'] for n in NETWORKS]:
abort(404)
else:
validator_data = get_validator_api_data(network, validator)
return jsonify({
"schema": SCHEMA,
"result": validator_data[1],
"last_update": validator_data[0]
})
if __name__ == '__main__':
app.run(host=API_HOST, port=API_PORT)