-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (54 loc) · 1.77 KB
/
main.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
import json
from flask import Flask, render_template, session, request
from src.spotify_auth import spotify_bp
from src.suggestions import suggestions_bp
from src.config import Config
# app
app = Flask(__name__)
app.secret_key = Config.FLASK_SESSION_SECRET_KEY
# routes
app.register_blueprint(spotify_bp)
app.register_blueprint(suggestions_bp)
@app.route('/')
def home_page():
messages = request.args.get('messages', None)
if messages is not None:
messages = json.loads(messages)
if 'user-name' in session:
user_details = {}
user_details['user-name'] = session['user-name']
user_details['user-email'] = session['user-email']
user_details['user-profile'] = session['user-profile']
user_details['access-token'] = session['access-token']
else:
user_details = None
if 'suggested_tracks' in session:
suggested_tracks = session['suggested_tracks']
user_prompt = session['user_prompt']
else:
suggested_tracks = None
user_prompt = None
if 'playlist_link' in session:
playlist_name = session['playlist_name']
playlist_link = session['playlist_link']
else:
playlist_link = None
playlist_name = None
return render_template(
'home.html',
home_url=f"{request.url_root}",
login_url=f"{request.url_root}/spotify-login",
logout_url=f"{request.url_root}/spotify-logout",
user_details=user_details,
messages=messages,
suggested_tracks=suggested_tracks,
playlist_link=playlist_link,
playlist_name=playlist_name,
user_prompt=user_prompt
)
if __name__ == "__main__":
app.run(
host=Config.HOST,
port=Config.PORT,
debug=True
)