def load(self): """ load a local file it must be a json file and the data format is the format exported by zoomeye. format is {"total":123123, "matches":[{...}, {...}, {...}...], "facets":{{...}, {...}...}} :param path: :return: """ data = file.read_file(self.dork) json_data = json.loads(data) self.total = json_data.get("total", 0) self.dork_data = json_data.get("matches", "") self.facet_data = json_data.get("facets", "") if self.total == 0 and self.dork_data == "" and self.facet_data: print("file format error!") exit(0) self.num = len(self.dork_data) return self.dork_data, self.facet_data, self.total
def get_data_from_cache(self): """ get data from local file """ # cache file exists if os.path.exists(self.cache_path): # file exists check expired time # expired time five day create_time = os.path.getatime(self.cache_path) if int(time.time()) - int(create_time) > config.EXPIRED_TIME: # over expired time remove file os.remove(self.cache_path) return None # read local file history_data = file.read_file(self.cache_path) return history_data # cache file not exists else: return None
def load(self): """ files in the cache from the local folder :return: """ result_data = [] facet_data = None read_data = file.read_file(self.filename) data_json = json.loads(read_data) """ process the data loaded from the cache file, the processed data structure is list. like: [{...}, {...},{...}...] """ for i in data_json.get("matches"): result_data.append(i) # get facet if data_json.get("facets"): facet_data = data_json.get("facets") # get data total total = data_json.get("total") # return return result_data, facet_data, total