本文整理汇总了Python中src.tools.db.DB.wrap方法的典型用法代码示例。如果您正苦于以下问题:Python DB.wrap方法的具体用法?Python DB.wrap怎么用?Python DB.wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类src.tools.db.DB
的用法示例。
在下文中一共展示了DB.wrap方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __get_question_list
# 需要导入模块: from src.tools.db import DB [as 别名]
# 或者: from src.tools.db.DB import wrap [as 别名]
def __get_question_list(self):
question_list = [DB.wrap('question', x) for x in DB.get_result_list(self.sql.question)]
answer_list = [DB.wrap('answer', x) for x in DB.get_result_list(self.sql.get_answer_sql())]
def merge_answer_into_question():
question_dict = {x['question_id']: {'question': x.copy(), 'answer_list': [], 'agree': 0} for x in
question_list}
for answer in answer_list:
question_dict[answer['question_id']]['answer_list'].append(answer)
return question_dict.values()
def add_property(question):
agree_count = 0
char_count = 0
for answer in question['answer_list']:
answer['char_count'] = len(answer['content'])
answer['agree_count'] = answer['agree']
answer['update_date'] = answer['edit_date']
agree_count += answer['agree']
char_count += answer['char_count']
question['answer_count'] = len(question['answer_list'])
question['agree_count'] = agree_count
question['char_count'] = char_count
return question
question_list = [add_property(x) for x in merge_answer_into_question() if len(x['answer_list'])]
return question_list
示例2: __get_article_list
# 需要导入模块: from src.tools.db import DB [as 别名]
# 或者: from src.tools.db.DB import wrap [as 别名]
def __get_article_list(self):
def add_property(article):
article['char_count'] = len(article['content'])
article['answer_count'] = 1
# TODO
if self.kind in [Type.jianshu_author, Type.jianshu_collection, Type.jianshu_notebooks,
Type.sinablog_author, Type.csdnblog_author]:
article['agree_count'] = "没有赞同数" # article['agree']
else:
article['agree_count'] = article['agree']
article['update_date'] = article['publish_date']
return article
if self.kind in [Type.jianshu_author, Type.jianshu_collection, Type.jianshu_notebooks]:
article_list = [DB.wrap(Type.jianshu_article, x) for x in DB.get_result_list(self.sql.get_answer_sql())]
elif self.kind == Type.sinablog_author:
article_list = [DB.wrap(Type.sinablog_article, x) for x in DB.get_result_list(self.sql.get_answer_sql())]
elif self.kind == Type.csdnblog_author:
article_list = [DB.wrap(Type.csdnblog_article, x) for x in DB.get_result_list(self.sql.get_answer_sql())]
else:
article_list = [DB.wrap(Type.article, x) for x in DB.get_result_list(self.sql.get_answer_sql())]
article_list = [add_property(x) for x in article_list]
return article_list
示例3: catch_article_book_info
# 需要导入模块: from src.tools.db import DB [as 别名]
# 或者: from src.tools.db.DB import wrap [as 别名]
def catch_article_book_info(self, sql):
info_list = DB.cursor.execute(self.sql.info).fetchall()
info_list = [DB.wrap(Type.article, item) for item in info_list]
info = {}
info['title'] = '_'.join([str(item['title']) for item in info_list])
info['id'] = '_'.join([str(item['article_id']) for item in info_list])
return info
示例4: catch_info
# 需要导入模块: from src.tools.db import DB [as 别名]
# 或者: from src.tools.db.DB import wrap [as 别名]
def catch_info(self):
info = {}
if self.property.sql.info:
info = DB.cursor.execute(self.property.sql.info).fetchone()
info = DB.wrap(Type.info_table[self.kind], info)
self.set_info(info)
return
示例5: catch_question_book_info
# 需要导入模块: from src.tools.db import DB [as 别名]
# 或者: from src.tools.db.DB import wrap [as 别名]
def catch_question_book_info(self, sql):
info_list = DB.cursor.execute(self.sql.info).fetchall()
info_list = [DB.wrap(Type.question, item) for item in info_list]
info = dict()
info['title'] = '_'.join([str(item['title']) for item in info_list]) # 可以是多个问题, 多个id联系在一起
info['id'] = '_'.join([str(item['question_id']) for item in info_list])
return info
示例6: __get_article_list
# 需要导入模块: from src.tools.db import DB [as 别名]
# 或者: from src.tools.db.DB import wrap [as 别名]
def __get_article_list(self):
def add_property(article):
article['char_count'] = len(article['content'])
article['agree_count'] = article['agree']
article['update_date'] = article['publish_date']
article['answer_count'] = 1
return article
article_list = [DB.wrap(Type.article, x) for x in DB.get_result_list(self.sql.get_answer_sql())]
article_list = [add_property(x) for x in article_list]
return article_list
示例7: catch_csdnblog_book_info
# 需要导入模块: from src.tools.db import DB [as 别名]
# 或者: from src.tools.db.DB import wrap [as 别名]
def catch_csdnblog_book_info(self):
u"""
:return:
"""
info_list = DB.cursor.execute(self.sql.info).fetchall()
info_list = [DB.wrap(Type.csdnblog_info, item) for item in info_list]
info = dict()
info['creator_name'] = '_'.join([str(item['creator_name']) for item in info_list])
info['creator_id'] = '_'.join([str(item['creator_id']) for item in info_list])
return info
示例8: catch_info
# 需要导入模块: from src.tools.db import DB [as 别名]
# 或者: from src.tools.db.DB import wrap [as 别名]
def catch_info(self):
info = {}
if self.sql.info:
if self.kind in [Type.question, Type.answer]:
info = self.catch_question_book_info(self.sql.info)
elif self.kind == Type.article:
info = self.catch_article_book_info(self.sql.info)
else:
info = DB.cursor.execute(self.sql.info).fetchone()
info = DB.wrap(Type.info_table[self.kind], info)
self.set_info(info)
return
示例9: catch_jianshu_book_info
# 需要导入模块: from src.tools.db import DB [as 别名]
# 或者: from src.tools.db.DB import wrap [as 别名]
def catch_jianshu_book_info(self):
u"""
:return: info
"""
info_list = DB.cursor.execute(self.sql.info).fetchall()
info_list = [DB.wrap(Type.jianshu_info, item) for item in info_list]
info = dict()
# 可以是多个博客组合在一起 TODO: 删掉???
info['creator_name'] = '_'.join([str(item['creator_name']) for item in info_list])
info['creator_id'] = '_'.join([str(item['creator_id']) for item in info_list])
return info
示例10: catch_sinablog_book_info
# 需要导入模块: from src.tools.db import DB [as 别名]
# 或者: from src.tools.db.DB import wrap [as 别名]
def catch_sinablog_book_info(self):
u"""
:param
:return: info
"""
info_list = DB.cursor.execute(self.sql.info).fetchall()
info_list = [DB.wrap(Type.sinablog_info, item) for item in info_list]
info = dict()
info['creator_name'] = '_'.join([str(item['creator_name']) for item in info_list]) # 可以是多个博客组合在一起
info['creator_id'] = '_'.join([str(item['creator_id']) for item in info_list])
return info
示例11: catch_info
# 需要导入模块: from src.tools.db import DB [as 别名]
# 或者: from src.tools.db.DB import wrap [as 别名]
def catch_info(self):
u"""
获得博客的信息, 将info作为参数传给set_info
:return:
"""
info = {}
if self.sql.info:
if self.kind == Type.csdnblog_author:
info = self.catch_csdnblog_book_info()
elif self.kind == Type.jianshu_author:
info = self.catch_jianshu_book_info()
elif self.kind == Type.sinablog_author:
info = self.catch_sinablog_book_info()
elif self.kind in [Type.question, Type.answer]:
info = self.catch_question_book_info(self.sql.info)
elif self.kind == Type.article:
info = self.catch_article_book_info(self.sql.info)
else:
info = DB.cursor.execute(self.sql.info).fetchone()
info = DB.wrap(Type.info_table[self.kind], info)
self.set_info(info)
return