-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
249 lines (149 loc) · 5.57 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
from flask import Flask,render_template, session, redirect, url_for, request
from httpx import URL
import requests
from uuid import uuid4
from flask_recaptcha import ReCaptcha
from os import getenv
app = Flask(__name__)
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'
app.config['RECAPTCHA_SITE_KEY'] = '6LffydYgAAAAAFYE9ZYRR31INacauICpvN4RsXZ0' # <-- Add your site key
app.config['RECAPTCHA_SECRET_KEY'] = '6LffydYgAAAAAHwuNObQB_yra8x4UGXtwld9C48d' # <-- Add your secret key
app.config['RECAPTCHA_THEME'] = "dark"
recaptcha = ReCaptcha(app)
global URl
URl = getenv("URL")
@app.route("/",methods = ["GET","POST"])
def main():
login = 0
try:
session["LoaderId"]
session["LoaderName"]
login= 0
except:
login = 1
try:
response = requests.get("{}/song/all".format(URl)).json()
songs = []
for i in response:
songs.append(i)
return render_template("/index.html", songs=songs, login=login)
except:
return render_template("/index.html", login=login)
@app.route("/create",methods = ["GET","POST"])
def create():
login = 0
try:
session["LoaderId"]
session["LoaderName"]
login= 0
except:
login = 1
return render_template("/create.html", login=login)
if request.method == "POST":
if recaptcha.verify()==False:
session["Flag"] = 1
session["Text"] = "Please verify that you are human."
return redirect(url_for("create"))
SongTittle = request.form['SongTittle']
Artist = request.form['Artist']
SongGenre = request.form['SongGenre']
createSong = {
"SongTittle": SongTittle,
"Artist": Artist,
"SongGenre": SongGenre,
"LoaderId": session["LoaderId"],
"LoaderName": session["LoaderName"]
}
response = requests.post("{}/song/create".format(URl), json = createSong)
session["Flag"] = 2
session["Text"] = "Song creation successful."
return redirect(url_for("create"))
else:
try:
if session["Flag"]==1 or session["Flag"]==2:
text = session["Text"]
flag = session["Flag"]
session["Flag"]=-1
session["Text"]=""
return render_template("/create.html", login=login, flag=flag, text=text)
else:
return render_template("/create.html", login=login, flag=-1)
except:
return render_template("/create.html", login=login, flag=-1)
@app.route("/mySongs",methods = ["GET","POST"])
def mySongs():
login = 0
try:
session["LoaderId"]
session["LoaderName"]
login= 0
except:
login = 1
return render_template("/mySongs.html", login=login)
response = requests.get("{}/song/get/".format(URl)+str(session["LoaderId"])).json()
songs = []
for i in response:
songs.append(i)
try:
if session["Flag"]==1 or session["Flag"]==2:
text = session["Text"]
flag = session["Flag"]
session["Flag"]=-1
session["Text"]=""
return render_template("/mySongs.html", login=login, songs=songs, flag=flag, text=text)
else:
return render_template("/mySongs.html", login=login, songs=songs, flag=-1)
except:
return render_template("/mySongs.html", login=login, songs=songs, flag=-1)
@app.route("/process",methods = ["GET","POST"])
def process():
login = 0
try:
session["LoaderId"]
session["LoaderName"]
login= 0
except:
login = 1
return render_template("/mySongs.html", login=login)
if request.method == "POST":
processType = request.form['processType']
if str(processType)=="0":
SongId = request.form['SongId']
LoaderId = session["LoaderId"]
json={"SongId": SongId,
"LoaderId":LoaderId}
response = requests.delete("{}/song/delete/".format(URl), json=json)
session["Flag"] = 2
session["Text"] = "Song deletion successful."
elif str(processType)=="1":
LoaderId = session["LoaderId"]
SongId = request.form['SongId']
Artist = request.form['Artist']
LoaderName = session["LoaderName"]
SongGenre = request.form['SongGenre']
SongProductionDate = request.form['SongProductionDate']
SongTittle = request.form['SongTittle']
json={"SongId":SongId,
"SongTittle":SongTittle,
"Artist":Artist,
"SongGenre":SongGenre,
"SongProductionDate":SongProductionDate,
"LoaderId": LoaderId,
"LoaderName":LoaderName
}
response = requests.put("{}/song/update/".format(URl), json=json)
session["Flag"] = 2
session["Text"] = "The song {} has been successfully updated.".format(SongTittle)
return redirect(url_for("mySongs"))
else:
return redirect(url_for("mySongs"))
@app.route("/login",methods = ["GET","POST"])
def login():
if request.method == "POST":
session["LoaderId"] = str(uuid4())
session["LoaderName"] = request.form['name']
return redirect(url_for("main"))
else:
return redirect(url_for("main"))
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000, debug=True)