Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
with open(name) as f:
print name
_file = f.read().decode('utf-8')
if _file:
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, '
'status) values '
'(?, ?, ?, ?, ?, ?, "draft")',
(title, slug, content, create_time,
category, tag))
db.commit()
except IOError as exc:
if exc.errno != errno.EISDIR:
raise
with open(name) as f:
print name
_file = f.read().decode('utf-8')
if _file:
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
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()
def before_request():
g.db = connect_db()
g.debug = True