-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
137 lines (97 loc) · 3.37 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from flask import Flask, redirect, url_for, session, request, render_template
from flask_session import Session
from datetime import timedelta
from time import sleep
import os
import redis
from rq import Queue
from rq.job import Job
from api.spotify_api import GenToken, GetCustomList, GetTracksSpecs, GetCode, CategoryPlaylist, GetFeaturedPlaylists, GetFeatItems
from api.xmatch_api import GetLyricsFromCustom, GetLyricsFromName
from api.model_api import PredictTop
app = Flask(__name__)
app.secret_key = 'spotify_secret'
app.permanent_session_lifetime = timedelta(minutes=5)
SESSION_TYPE = 'filesystem'
app.config.from_object(__name__)
Session(app)
spotify_scope = "user-read-recently-played"
def internal_error(e):
return redirect(url_for('home'))
app.register_error_handler(500, internal_error)
@app.route('/')
def index():
return redirect(url_for('home'))
@app.route('/test')
def test():
return CategoryPlaylist(session['token'], 'sad')
@app.route('/login', methods=['GET', 'POST'])
def login():
return redirect(GetCode())
@app.route('/login/authorized')
def spotify_authorized():
session['token'] = GenToken(request.args.get('code')).json()
return redirect(url_for('home'))
@app.route('/getrecentsession')
def getrecentsession():
session.permanent = True
custom = GetCustomList(session['token'])
session['songs'] = GetLyricsFromCustom(custom)
print(session['songs'])
return redirect(url_for('home'))
@app.route('/featuredplaylists')
def featuredplaylists():
session.permanent = True
feat = GetFeaturedPlaylists(session['token'])
return GetFeatItems(session['token'], feat)
@app.route('/listplayed')
def listplayed():
session.permanent = True
return GetCustomList(session['token'])
@app.route('/listplayedlyrical')
def listplayedlyrical():
session.permanent = True
custom = GetCustomList(session['token'])
return GetLyricsFromCustom(custom)
@app.route('/listplayedfeatures')
def listplayedfeatures():
session.permanent = True
custom = GetCustomList(session['token'])
return GetTracksSpecs(session['token'], custom)
@app.route('/listplayedfull')
def listplayedfull():
session.permanent = True
custom = GetCustomList(session['token'])
custom = GetTracksSpecs(session['token'], custom)
return GetLyricsFromCustom(custom)
@app.route('/home')
def home():
session['running'] = 1
return render_template('index.html')
@app.route('/api')
def api():
return render_template('index_api.html')
@app.route('/anya')
def anya():
if session['running'] == 1:
session['song_list'] = listplayedfull()
red = redis.from_url(os.environ.get("REDIS_URL"))
q = Queue(connection=red)
job = q.enqueue(PredictTop, session['song_list'])
session['job_id'] = job.id
session['running'] = 2
red = redis.from_url(os.environ.get("REDIS_URL"))
job = Job.fetch(session['job_id'], connection=red)
if job.result == None:
return render_template('intermediate.html',
value=job,
id=session['job_id'])
session['running'] = 1
return render_template('intermediate2.html',
value=job,
id=session['job_id'])
@app.route('/lyrics')
def lyrics():
return GetLyricsFromName(request.args.get('name'))
if __name__ == "__main__":
app.run()