-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
73 lines (61 loc) · 1.8 KB
/
manage.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
#coding:utf-8
import sys
import importlib
import os
import time
import xlrd
from muxibook_app import create_app,db
from muxibook_app.models import User,Book,Kind
from flask_script import Manager,Shell,Command
from flask_migrate import Migrate,MigrateCommand
importlib.reload(sys)
#export PYTHONIOENCODING = "UTF-8"
app=create_app(os.getenv('FLASK_CONFIG') or 'default')
manager=Manager(app)
migrate=Migrate(app,db)
manager.add_command('db',MigrateCommand)
class get_info(Command):
def run(self):
book=xlrd.open_workbook("1.xls")
sheets=book.sheets()
for sheet in sheets:
rows=sheet.get_rows()
c=0
for row in rows :
c+=1
if c>1:
s=row[2].value.encode('utf-8').decode('utf-8')
a=Book(ava=1,kind_id=row[0].value,book_num=row[1].value,bookname=s)
db.session.add(a)
db.session.commit()
print ("Get_info Successful!")
manager.add_command('get_info',get_info())
class kind_init(Command):
def run(self):
a=Kind()
b=Kind()
c=Kind()
d=Kind()
e=Kind()
f=Kind()
db.session.add(a)
db.session.add(b)
db.session.add(c)
db.session.add(d)
db.session.add(e)
db.session.add(f)
db.session.commit()
print ("Kind_init Successful!")
manager.add_command('kind_init',kind_init())
def make_shell_context():
return dict(app=app)
manager.add_command("shell",Shell(make_context=make_shell_context))
@manager.command
def test():
"""run your unit tests"""
import unittest
tests=unittest.TestLoader().discover('test')
unittest.TextTestRunner(verbosity=2).run(tests)
if __name__=='__main__':
manager.run()
app.run(debug=True)