Пример #1
0
def fill_post():
    files = glob.glob('./summer/post/*.md')

    for name in files:
        try:
            with open(name) as f:
                print name
                _file = f.read().decode('utf-8')
                meta = _file.split('---')[0]
                content = _file.split('---')[1]

                title = yaml.load(meta)['title']
                slug = os.path.splitext(ntpath.basename(f.name))[0]
                create_time = yaml.load(meta)['date']
                category = (','.join(yaml.load(meta)['categories'])
                            if yaml.load(meta)['categories'] else '')
                tag = (','.join(yaml.load(meta)['tags'])
                       if yaml.load(meta)['tags'] else '')

                with closing(connect_db()) as db:
                    db.execute('insert into entries (title, slug, content, '
                               'create_time, category, tag) values '
                               '(?, ?, ?, ?, ?, ?)',
                               [title, slug, content, create_time,
                                category, tag])
                    db.commit()

        except IOError as exc:
            if exc.errno != errno.EISDIR:
                raise
Пример #2
0
def fill_post():
    files = glob.glob('./summer/post/*.md')

    for name in files:
        try:
            with open(name) as f:
                print name
                _file = f.read().decode('utf-8')
                meta = _file.split('---')[0]
                content = _file.split('---')[1]

                title = yaml.load(meta)['title']
                slug = os.path.splitext(ntpath.basename(f.name))[0]
                create_time = yaml.load(meta)['date']
                category = (','.join(yaml.load(meta)['categories'])
                            if yaml.load(meta)['categories'] else '')
                tag = (','.join(yaml.load(meta)['tags'])
                       if yaml.load(meta)['tags'] else '')

                with closing(connect_db()) as db:
                    db.execute(
                        'insert into entries (title, slug, content, '
                        'create_time, category, tag) values '
                        '(?, ?, ?, ?, ?, ?)',
                        [title, slug, content, create_time, category, tag])
                    db.commit()

        except IOError as exc:
            if exc.errno != errno.EISDIR:
                raise
Пример #3
0
def init_db():
    app = create_app("product")
    _context = app.app_context()
    _context.push()
    with closing(connect_db()) as db:
        with open("./summer/schema.sql", mode="r") as f:
            db.cursor().executescript(f.read())
            db.commit()
Пример #4
0
def init_db():
    app = create_app('product')
    _context = app.app_context()
    _context.push()
    with closing(connect_db()) as db:
        with open('./summer/schema.sql', mode='r') as f:
            db.cursor().executescript(f.read())
            db.commit()
Пример #5
0
def init_db():
    with closing(connect_db()) as db:
        with open('./summer/schema.sql', mode='r') as f:
            db.cursor().executescript(f.read())
            db.commit()
Пример #6
0
def init_db():
    with closing(connect_db()) as db:
        with open('./summer/schema.sql', mode='r') as f:
            db.cursor().executescript(f.read())
            db.commit()