Example #1
0
    def __get_question_list(self):
        question_list = [SqlClass.wrap('question', x) for x in SqlClass.get_result_list(self.book_info['question'])]
        answer_list = [SqlClass.wrap('answer', x) for x in SqlClass.get_result_list(self.book_info['answer'])]

        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'])
            question['agree_count'] = agree_count
            question['char_count'] = char_count
            return question

        question_list = [add_property(x) for x in merge_answer_into_question()]
        return question_list
Example #2
0
 def clear_index(self):
     topic_id_tuple = tuple(
         set(x['topic_id'] for x in self.topic_index_list))
     sql = 'DELETE  from TopicIndex where topic_id in ({})'.format(
         (' ?,' * len(topic_id_tuple))[:-1])
     SqlClass.cursor.execute(sql, topic_id_tuple)
     SqlClass.commit()
     return
Example #3
0
 def save(self):
     self.clear_index()
     save_config = self.create_save_config()
     for key in save_config:
         for item in save_config[key]:
             if item:
                 SqlClass.save2DB(item, key)
     SqlClass.commit()
     return
Example #4
0
 def save(self):
     self.clear_index()
     save_config = self.create_save_config()
     for key in save_config:
         for item in save_config[key]:
             if item:
                 SqlClass.save2DB(item, key)
     SqlClass.commit()
     return
Example #5
0
    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 = [SqlClass.wrap('article', x) for x in SqlClass.get_result_list(self.raw_info['answer'])]
        article_list = [add_property(x) for x in article_list]
        return article_list
Example #6
0
 def clear_index(self):
     topic_id_tuple = tuple(set(x['topic_id'] for x in self.topic_index_list))
     sql = 'DELETE  from TopicIndex where topic_id in ({})'.format((' ?,' * len(topic_id_tuple))[:-1])
     SqlClass.cursor.execute(sql, topic_id_tuple)
     SqlClass.commit()
     return
Example #7
0
 def create_info_page(self, kind, info_sql):
     with open('./html_template/info/{}.html'.format(kind)) as file:
         template = file.read()
     result = SqlClass.cursor.execute(info_sql).fetchone()
     info = self.create_info_dict(kind, SqlClass.wrap(kind, result))
     return template.format(info)
Example #8
0
 def get_info(self):
     info = dict()
     if self.book_info['info']:
         info = SqlClass.cursor.execute(self.book_info['info']).fetchone()
         info = SqlClass.wrap(TypeClass.info_table[self.kind], info)
     return info