-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathapp.py
51 lines (36 loc) · 1.24 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
from flask import render_template, Flask
from datafoo import spotify
app = Flask(__name__)
@app.route('/')
def homepage():
html = render_template('homepage.html')
return html
@app.route('/search/<name>')
def search(name):
data = spotify.search_by_artist_name(name)
api_url = data['artists']['href']
items = data['artists']['items']
html = render_template('search.html',
artist_name=name,
results=items,
api_url=api_url)
return html
@app.route('/artist/<id>')
def artist(id):
artist = spotify.get_artist(id)
if artist['images']:
image_url = artist['images'][0]['url']
else:
image_url = 'http://placecage.com/600/400'
tracksdata = spotify.get_artist_top_tracks(id)
tracks = tracksdata['tracks']
artistsdata = spotify.get_related_artists(id)
relartists = artistsdata['artists']
html = render_template('artist.html',
artist=artist,
related_artists=relartists,
image_url=image_url,
tracks=tracks)
return html
if __name__ == '__main__':
app.run(use_reloader=True, debug=True)