def pull(comic_id=505432): """ pull a comic from MAC :param comic_id: 505432 for naruto """ with current_app.app_context(): ac_client = current_app.ac_client current_app.logger.info( 'Pull Comic<id::{}> from m.ac.qq.com'.format(comic_id)) summary = ac_client.Comic.summary(comic_id) summary['external_id'] = summary.pop('id') c = Comic() c.fromdict(schema_comic.deserialize(summary)) current_app.db.session.add(c) current_app.db.session.commit() chapters = ac_client.Chapter.list(comic_id) for chapter in chapters: current_app.db.session.add( Chapter(c.id, chapter.get('t'), chapter.get('seq'))) current_app.db.session.commit()
def init_db(): with current_app.app_context(): folder_name = app.config.get('INIT_DATA_FOLDER_NAME') folder_path = ResourceLoader.get().get_resoure(folder_name).path if folder_path and os.path.isdir(folder_path): for data_file in os.listdir(folder_path): with open(folder_path + os.path.sep + data_file, 'r') as mqls: get_db().eval(mqls.read())
def init_db(): with current_app.app_context(): db.create_all() folder_path = ResourceLoader.get().get_resoure('init-sql').path if folder_path and os.path.isdir(folder_path): for data_file in os.listdir(folder_path): with open(folder_path + os.path.sep + data_file, 'r') as mqls: db.engine.execute(mqls.read())
def clear_db(): with current_app.app_context(): db.drop_all()
def cleardb(): """Clear database .""" with current_app.app_context(): clear_db()
def initdb(): """ Initialize database . """ with current_app.app_context(): init_db()
def clear_db(): with current_app.app_context(): get_db().eval('db.dropDatabase()')
def cleardb(): '''Clear database .''' with current_app.app_context(): clear_db()
def initdb(): ''' Initialize database . ''' with current_app.app_context(): init_db()