import json from flask import request, Response from project_name.app import application from project_name.model import persister from project_name.util.sql_alchemy_json_encoder import SQLAlchemyJSONEncoder @application.route('/') def index(): return application.send_static_file('index.html') @application.route('/hello', methods=['GET']) def hello_world(): return 'Hello From Flask Handlers', 200 @application.route('/top_tracks', methods=['GET']) def query_db(): user_country = request.args.get('country', None) genre = request.args.get('genre', None) subgenre = request.args.get('subgenre', None) top_n_tracks = int(request.args.get('top_n_tracks', 5)) lower_threshold = int(request.args.get('lower_threshold', 150)) res = persister.get_spotify_trend_from_db( genre_id=genre, subgenre_id=subgenre, country_code=user_country, top_n_tracks=top_n_tracks, lower_threshold=lower_threshold) return Response(response=json.dumps(res, cls=SQLAlchemyJSONEncoder), status=200, mimetype="application/json") @application.route('/countries', methods=['GET']) def countries(): res = persister.get_countries_from_db() return Response(response=json.dumps(res, cls=SQLAlchemyJSONEncoder), status=200, mimetype="application/json") @application.route('/genres', methods=['GET']) def genres(): res = persister.get_genres() return Response(response=json.dumps(res, cls=SQLAlchemyJSONEncoder), status=200, mimetype="application/json") @application.route('/subgenres', methods=['GET']) def subgenres(): genre_id = request.args.get('genre_id', None) res = persister.get_subgenres(genre_id) return Response(response=json.dumps(res, cls=SQLAlchemyJSONEncoder), status=200, mimetype="application/json")