def _init_statistical_data(self): '''初始化说说、相册、留言板、日志数量 ''' if not self._files[QzonePath.MSG_BOARD]: self._files[QzonePath.MSG_BOARD] = get_files( self._data_dir[QzonePath.MSG_BOARD], test_msgboard_valid) self._sum_page[QzonePath.MSG_BOARD] = get_sum_page( self._files[QzonePath.MSG_BOARD]) self._main_data[QzonePath.MSG_BOARD] = self._sum_page[ QzonePath.MSG_BOARD][len(self._files[QzonePath.MSG_BOARD])] self._total_page[QzonePath.MSG_BOARD] = len( self._files[QzonePath.MSG_BOARD]) main_page_file_name = "%s_main_page.json" % self._main_dir filename = os.path.join(self._main_dir, main_page_file_name) if not os.path.exists(filename): return json_data = None with open(filename, "r", encoding="utf-8") as fin: json_data = json.load(fin) if json_data is None: return data = json_data["data"]["module_16"]["data"] self._main_data[QzonePath.SHUOSHUO] = data["SS"] self._main_data[QzonePath.BLOG] = data["RZ"] self._main_data[QzonePath.PHOTO] = data["XC"]
def _init_blog_data(self): '''初始化日志数据 ''' self._new_blog_info = {} self._blog_info_list = [] self._comment_files[QzonePath.BLOG] = {} self._files[QzonePath.BLOG] = {} categories = os.listdir(self._data_dir[QzonePath.BLOG]) for encoded_cate in categories: encoded_cate_dir = os.path.join(self._data_dir[QzonePath.BLOG], encoded_cate) if not os.path.isdir(encoded_cate_dir): blogs_info_filename = encoded_cate_dir if not test_blog_info_valid(encoded_cate): continue with open(blogs_info_filename, "r", encoding="utf-8") as fin: blogs_data = json.load(fin) for blog in blogs_data.get("data", {}).get("list", []): self._new_blog_info[blog["blogId"]] = blog continue files = os.listdir(encoded_cate_dir) for encoded_file in files: s = test_blog_valid(encoded_file) if not s: continue blog_info = get_blog_info(self._data_dir[QzonePath.BLOG], encoded_cate, encoded_file, s) if not blog_info: continue self._blog_info_list.append(blog_info) self._files[QzonePath.BLOG].setdefault( blog_info.category, {})[blog_info.blog_id] = blog_info self._comment_files[QzonePath.BLOG][encoded_file] = [] for encoded_file in files: s = test_blog_comment_valid(encoded_file) if not s: continue html_f = "%s.html" % s[1] self._comment_files[QzonePath.BLOG].setdefault( html_f, []).append(encoded_file) for k, v in self._comment_files[QzonePath.BLOG].items(): self._comment_files[QzonePath.BLOG][k] = sorted(v) self._sum_page[QzonePath.BLOG][k] = \ get_sum_page(self._comment_files[QzonePath.BLOG][k]) self._total_page[QzonePath.BLOG][k] = len(v) self._blog_info_list = sort_blog_list_by_time(self._blog_info_list) self._main_data[QzonePath.BLOG] = len(self._blog_info_list)
def _init_blog_data(self): '''初始化日志数据 ''' self._blog_info_list = [] self._comment_files[QzonePath.BLOG] = {} self._files[QzonePath.BLOG] = {} categories = os.listdir(self._data_dir[QzonePath.BLOG]) for encoded_cate in categories: encoded_cate_dir = os.path.join( self._data_dir[QzonePath.BLOG], encoded_cate) if not os.path.isdir(encoded_cate_dir): continue files = os.listdir(encoded_cate_dir) for encoded_file in files: s = test_blog_valid(encoded_file) if not s: continue blog_info = get_blog_info( self._data_dir[QzonePath.BLOG], encoded_cate, encoded_file, s) if not blog_info: continue self._blog_info_list.append(blog_info) self._files[QzonePath.BLOG].setdefault( blog_info.category, {})[blog_info.blog_id] = blog_info self._comment_files[QzonePath.BLOG][encoded_file] = [] for encoded_file in files: s = test_blog_comment_valid(encoded_file) if not s: continue html_f = "%s.html" % s[1] self._comment_files[QzonePath.BLOG].setdefault( html_f, []).append(encoded_file) for k, v in self._comment_files[QzonePath.BLOG].items(): self._comment_files[QzonePath.BLOG][k] = sorted(v) self._sum_page[QzonePath.BLOG][k] = \ get_sum_page(self._comment_files[QzonePath.BLOG][k]) self._total_page[QzonePath.BLOG][k] = len(v) self._blog_info_list = sort_blog_list_by_time(self._blog_info_list) self._main_data[QzonePath.BLOG] = len(self._blog_info_list)