-
Notifications
You must be signed in to change notification settings - Fork 6
/
cli.py
53 lines (45 loc) · 1.53 KB
/
cli.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
from datetime import datetime
import logging
import click
from app.models import User,Video,Role,Videocol
from app import db
def register(app):
@app.cli.command("create_user")
@click.argument("username")
def create_user(username):
user = User(name=username)
db.session.add(user)
db.session.commit()
@app.cli.command("create_videocol")
@click.argument("userid")
@click.argument("videoid")
def create_videocol(userid,videoid):
videocol = Videocol(videoid, userid)
db.session.add(videocol)
db.session.commit()
@app.cli.command("create_role")
@click.argument("rolename")
def create_role(rolename):
role = Role(name=rolename)
db.session.add(role)
db.session.commit()
@app.cli.command("add_video")
@click.argument("video_title")
@click.argument("video_info")
@click.argument("video_likenum")
def add_video(video_title,video_info,video_likenum):
video = Video(title=video_title,
info=video_info,playnum=0,likenum=0,commentnum=0,
collectionnum=0,coinnum=0,
length=0,danmu_path=None,uploaduser_id=None)
video.url = "static/video/"+video_title+".mp4"
video.thumbnail = "/static/images/thumbnail/"+video.title+".jpg"
video.uploadtime = datetime.utcnow()
db.session.add(video)
db.session.commit()
@app.cli.command("delete_all")
def delete_all():
db.drop_all()
@app.cli.command("create_all")
def create_all():
db.create_all()