-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
95 lines (73 loc) · 3.69 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from flask import Flask, render_template, request
import geohash2
import requests
import os
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/eventsData', methods=['GET', 'POST'])
def eventsData():
if request.method == 'POST':
data = request.get_json()
print(data)
return data
@app.route('/eventData/<numEvent>')
def eventData(numEvent):
return render_template('eventData.html')
@app.route('/event', methods=['GET', 'POST'])
def event():
if request.method == 'POST':
data = request.get_json()
geoPoint = geohash2.encode(float(data['latitude']), float(data['longitude']), precision=9)
API_KEY = os.environ['API_KEY']
radius = 5000
events = requests.get(f'https://app.ticketmaster.com/discovery/v2/events.json?geoPoint={geoPoint}&radius={radius}&unit=km&apikey={API_KEY}')
print(f'https://app.ticketmaster.com/discovery/v2/events.json?geoPoint={geoPoint}&radius={radius}&unit=km&apikey={API_KEY}')
events = events.json()
eventsNames = []
if '_embedded' in events:
events = events['_embedded']['events']
for event in events:
data = {}
try: data['name'] = event['name']
except: data['name'] = None
try: data['image'] = event['images'][0]['url']
except: data['image'] = None
try: data['distance'] = event['distance']
except: data['distance'] = None
try: data['city'] = event['_embedded']['venues'][0]['city']['name']
except: data['city'] = None
try: data['date'] = event['dates']['start']['localDate']
except: data['date'] = None
try: data['hour'] = event['dates']['start']['localTime']
except: data['hour'] = 0
try: data['classif'] = event['classifications'][0]['segment']['name']
except: data['classif'] = None
eventsNames.append(data)
#eventsNames = [{'name': event['name'], 'image': event['images'][0]['url'], 'distance': event['distance'], 'city': event['_embedded']['venues'][0]['city']['name'], 'date': event['dates']['start']['localDate'], 'hour': None} if 'localTime' not in event['dates']['start'] else {'name': event['name'], 'image': event['images'][0]['url'], 'distance': event['distance'], 'city': event['_embedded']['venues'][0]['city']['name'], 'date': event['dates']['start']['localDate'], 'hour': event['dates']['start']['localTime']} for event in events]
else:
return {'description': 'ERROR'}, 500
formatedEvents = {}
for event in eventsNames:
if f"{event['name']} {event['city']}" in formatedEvents:
formatedEvents[f"{event['name']} {event['city']}"]["dates"].append({
"hour": event['hour'],
"date": event['date']
})
else:
formatedEvents[f"{event['name']} {event['city']}"] = {
'name': event['name'],
'image': event['image'],
'city': event['city'],
'distance': event['distance'],
'dates': [{'hour': event['hour'], 'date': event['date']}],
'class': event['classif']
}
#print(formatedEvents)
return formatedEvents, 200
@app.route('/events')
def events():
return render_template('events.html',)
if __name__ == "__main__":
app.run(debug=True)