Modify backend app
- add download route - combine chart endpoints to single get_json route
This commit is contained in:
parent
1ef277edc5
commit
198ab2a1f8
|
@ -1,10 +1,12 @@
|
|||
from flask import Flask, request, json, Response
|
||||
from flask import Flask, jsonify, request, json, Response, send_from_directory, abort
|
||||
from flask_cors import CORS
|
||||
import orjson
|
||||
import orjson, os
|
||||
|
||||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
|
||||
FILES_DIRECTORY = '../data/'
|
||||
|
||||
@app.route('/bitcoin_business_growth_by_country', methods=['GET'])
|
||||
def business_growth():
|
||||
# Parse args from request
|
||||
|
@ -36,45 +38,26 @@ def business_growth():
|
|||
# Return json
|
||||
return Response(json.dumps(sorted_data), mimetype='application/json')
|
||||
|
||||
@app.route('/price', methods=['GET'])
|
||||
def price():
|
||||
@app.route('/get_json/<filename>', methods=['GET'])
|
||||
def get_json(filename):
|
||||
file_path = os.path.join(FILES_DIRECTORY, filename)
|
||||
if not os.path.isfile(file_path):
|
||||
abort(404)
|
||||
|
||||
# Open json locally
|
||||
with open('../data/final__price.json', 'rb') as f:
|
||||
data = orjson.loads(f.read())
|
||||
with open(file_path, 'r') as file:
|
||||
data = json.load(file)
|
||||
|
||||
# Return json
|
||||
return Response(json.dumps(data), mimetype='application/json')
|
||||
return jsonify(data)
|
||||
|
||||
@app.route('/miner_rewards', methods=['GET'])
|
||||
def miner_rewards():
|
||||
@app.route('/download/<filename>', methods=['GET'])
|
||||
def download_file(filename):
|
||||
try:
|
||||
return send_from_directory(FILES_DIRECTORY, filename, as_attachment=True)
|
||||
except FileNotFoundError:
|
||||
abort(404)
|
||||
|
||||
# Open json locally
|
||||
with open('../data/final__miner_rewards.json', 'rb') as f:
|
||||
data = orjson.loads(f.read())
|
||||
|
||||
# Return json
|
||||
return Response(json.dumps(data), mimetype='application/json')
|
||||
|
||||
@app.route('/hashrate', methods=['GET'])
|
||||
def hashrate():
|
||||
|
||||
# Open json locally
|
||||
with open('../data/dev/final__hashrate.json', 'rb') as f:
|
||||
data = orjson.loads(f.read())
|
||||
|
||||
# Return json
|
||||
return Response(json.dumps(data), mimetype='application/json')
|
||||
|
||||
@app.route('/feerates', methods=['GET'])
|
||||
def feerates():
|
||||
|
||||
# Open json locally
|
||||
with open('../data/final__feerate_percentiles.json', 'rb') as f:
|
||||
data = orjson.loads(f.read())
|
||||
|
||||
# Return json
|
||||
return Response(json.dumps(data), mimetype='application/json')
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
|
|
Loading…
Reference in New Issue