forked from shea256/angular-flask
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage.py
41 lines (32 loc) · 885 Bytes
/
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
import os
import json
import argparse
import requests
from angular_flask.core import db
from angular_flask import app, models
from angular_flask.models import *
from peewee import *
from flask.ext.script import Manager
manager = Manager(app)
@manager.command
def create_db():
Post.create_table(fail_silently = True)
@manager.command
def drop_db():
Post.delete_table(fail_silently = True)
@manager.command
def seed_db():
with open('data/db_items.json', 'r') as f:
seed_data = json.loads(f.read())
for item_class in seed_data:
items = seed_data[item_class]
print items
for item in items:
print item
Post.create(title = item["title"], body = item["body"], pub_date=datetime.now())
print '\nSample data added to database!'
@manager.shell
def make_shell_context():
return dict(app=app, db=db, models=models)
if __name__ == "__main__":
manager.run()