-
Notifications
You must be signed in to change notification settings - Fork 1
/
tasks.py
49 lines (40 loc) · 1.07 KB
/
tasks.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
# pylint: disable=E1101
from invoke import task
from main import app, db
from json import loads
@task()
def rdb(c):
"""
Reload database
"""
with app.app_context():
db.db.drop_all()
db.db.create_all()
@task(rdb)
def load(c):
"""
Load test dataset
"""
def load(path, class_to_load):
with open(path) as f:
data = loads(f.read())
with app.app_context():
for obj in data:
db.db.session.add(class_to_load.load(obj))
db.db.session.commit()
load("resources/private/dishes.json", db.Dish)
load("resources/private/cafes.json", db.Cafe)
load("resources/private/employees.json", db.Employee)
load("resources/private/ingredients.json", db.Ingredient)
@task()
def show_emps(c):
"""
Display employees login and token
"""
with app.app_context():
emps = db.Employee.query.all()
for emp in emps:
print("{}:{}".format(emp.login, emp.token))
@task()
def run(c):
app.run(host="0.0.0.0", port=5000, debug=True)