from flask import Flask from flask import request import os import requests from geolib import geohash app = Flask(__name__) app._static_folder = os.path.abspath('static/') @app.route('/') def homepage(): return app.send_static_file('events.html') @app.route('/search', methods=['GET']) def search_for_events(): segmentIDMap = {'music': 'KZFzniwnSyZfZ7v7nJ', 'sports': 'KZFzniwnSyZfZ7v7nE', 'arts_theatre': 'KZFzniwnSyZfZ7v7na', 'film': 'KZFzniwnSyZfZ7v7nn', 'miscellaneous': 'KZFzniwnSyZfZ7v7n1'} #searchJSON = json.loads(searchInfo) requestJSON = {'apikey':'qkbDvyaw0KZXm7BZ6hEHAFS6rXVlAlaI', 'unit': 'miles'} requestJSON['keyword'] = request.args.get('keyword') if request.args.get('category') != 'default': requestJSON['segmentId'] = segmentIDMap[request.args.get('category')] requestJSON['radius'] = request.args.get('distance', type = int) requestJSON['geoPoint'] = geohash.encode(request.args.get('lat', type = float), request.args.get('lng', type = float), 7) eventResults = requests.get('https://app.ticketmaster.com/discovery/v2/events.json', params=requestJSON) return eventResults.json() @app.route('/eventdetail/<string:eventId>', methods = ['GET']) def get_event_detail(eventId): eventDetail = requests.get('https://app.ticketmaster.com/discovery/v2/events/' + eventId, params={'apikey':'qkbDvyaw0KZXm7BZ6hEHAFS6rXVlAlaI'}) return eventDetail.json() @app.route('/venuedetail/<string:venueName>', methods = ['GET']) def get_venue_detail(venueName): venueDetail = requests.get('https://app.ticketmaster.com/discovery/v2/venues/', params = {'apikey':'qkbDvyaw0KZXm7BZ6hEHAFS6rXVlAlaI', 'keyword': venueName}) return venueDetail.json() if __name__ == '__main__': app.run(debug=True)