-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
60 lines (48 loc) · 1.81 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
import falcon
import json
import flighthandlerasync
from falcon.http_status import HTTPStatus
class SilenceCORS(object):
def process_request(self, req, resp):
resp.set_header('Access-Control-Allow-Origin', '*')
resp.set_header('Access-Control-Allow-Methods', '*')
resp.set_header('Access-Control-Allow-Headers', '*')
resp.set_header('Access-Control-Max-Age', 1728000) # 20 days
if req.method == 'OPTIONS':
raise HTTPStatus(falcon.HTTP_200, body='\n')
class SpotifyConfigResource:
def on_get(self, req, resp):
"""send over the client_id"""
# this probably isn't good
secrets = json.load(open('secrets.json', 'r'))
resp.media = {
'client_id': secrets['client_id']
}
class TripResolverResource:
def on_post(self, req, resp):
# from the frontend: this will contain a spotify token and an array of artists
# second param: array of keywords
res = flighthandlerasync.get_gigs([artist['name'] for artist in req.media['artists']])
resp.media = res
class TripResolverResourceMock:
def on_post(self, req, resp):
print(req.media)
import time
time.sleep(2)
resp.media = json.load(open('./trip3.json'))
class QuoteResource:
def on_get(self, req, resp):
"""Handles GET requests"""
quote = {
'quote': (
"I've always been more interested in "
"the future than in the past."
),
'author': 'Grace Hopper'
}
resp.media = quote
api = falcon.API(middleware=[SilenceCORS()])
api.add_route('/quote', QuoteResource())
api.add_route('/spotify/config', SpotifyConfigResource())
api.add_route('/trip', TripResolverResource())
#api.add_route('/trip', TripResolverResourceMock())