-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
109 lines (72 loc) · 2.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
from flask import Flask,request,render_template
from download import Download
from flask_wtf import FlaskForm
from wtforms import FileField,SubmitField
from werkzeug.utils import secure_filename
import os
import zipfile
import io
from email.message import EmailMessage
import ssl
import smtplib
app = Flask(__name__)
# app.config['UPLOAD_FOLDER']='static/files'
@app.route('/')
def index():
return render_template('index.html')
@app.route('/',methods=['GET','POST'])
def getValue():
# data=request.form
singer=request.form['singer']
Number=request.form['number']
Number=int(Number)
duration=request.form['duration']
email=request.form['mail']
# f=request.files['filename']
# f.save(os.path.join(os.path.abspath(os.path.dirname(__file__)),app.config['UPLOAD_FOLDER'], secure_filename(f.filename)))
# file = "static/files/"+f.filename
# print(singer)
# print(Number)
# print(duration)
# print(email)
# print(data)
try:
Download(singer,Number,duration)
except:
return render_template('error.html')
# result.to_csv("static/files/result.csv",index=False)
email_sender = '[email protected]'
email_password = 'luteqppisuwuikis'
buffer = io.BytesIO()
with zipfile.ZipFile(buffer, 'w') as myzip:
myzip.write(f"static/{singer}/mashup.mp3", arcname="mashup.mp3")
buffer.seek(0)
with open(f"static/{singer}/mashup.zip", "wb") as f:
f.write(buffer.read())
em = EmailMessage()
em['From'] = email_sender
em['Subject'] = 'Your mashup'
em.set_content("Here is your Mashup")
with open(f"static/{singer}/mashup.zip","rb") as fp:
file_data=fp.read()
em.add_attachment(file_data,maintype='application',subtype='mp3',filename="mashup.zip")
context = ssl.create_default_context()
email_receiver =email
em['To'] =email_receiver
with smtplib.SMTP_SSL('smtp.gmail.com', 465, context=context) as smtp:
smtp.login(email_sender, email_password)
smtp.send_message(em)
return render_template('pass.html')
# @app.route('/dataset',methods=['GET','POST'])
# def dataset():
# file=request.form['file']
# data=[]
# with open(file) as f:
# csvfile=csv.reader(f)
# for row in csvfile:
# data.append(row)
# print(data)
# return render_template('dataset.html',dataset=data)
if __name__ == '__main__':
app.run(debug=True)