forked from AlotOfBlahaj/Auto_Record_Matsuri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.py
46 lines (36 loc) · 1.37 KB
/
web.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
from flask import Flask, render_template, redirect
from flask_pymongo import PyMongo, ObjectId
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import ValidationError, URL
app = Flask(__name__)
app.config['SECRET_KEY'] = 'test'
app.config["MONGO_URI"] = "mongodb://149.129.79.176:27017/Video"
db = PyMongo(app)
@app.route('/', methods=['GET', 'POST'])
def index():
ref = None
form = RefForm()
finished_live = db.db.Video.find()
queues = db.db.Queues.find()
if form.validate_on_submit():
ref = form.ref.data
form.ref.data = ''
db.db.Queues.insert({'Link': ref})
return redirect('/')
return render_template('index.html', form=form, ref=ref, queues=queues, finished_live=finished_live)
@app.route('/delete/<_id>')
def delete(_id):
db.db.Queues.delete_one({"_id": ObjectId(_id)})
return redirect('/')
class RefForm(FlaskForm):
ref = StringField('Youtube链接', validators=[URL])
submit = SubmitField('提交')
def validate_ref(self, field):
data = field.data
if 'www.youtube.com/watch?v=' not in data:
raise ValidationError("Error: You need to input a Youtube LIVE link")
if 'https://' not in data:
raise ValidationError("Error: You need to input a link with 'https://'")
if __name__ == '__main__':
app.run(debug=True)