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
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
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