class FileSpiderStorage(): def __init__(self): self.file_utils = FileUtils() self.base_path = './yuantacat/data/' def set(self, key, url): filepath = self.__build_filepath(key) self.file_utils.copy_url_to_file(url, filepath) def contains(self, key): filepath = self.__build_filepath(key) return self.file_utils.is_file(filepath) def get(self, key): filepath = self.__build_filepath(key) return self.file_utils.read_file(filepath) def __build_filepath(self, key): relative_path = '''{key}.html'''.format(key=key) return self.file_utils.join_paths(self.base_path, relative_path)
class DataCreator(): def __init__(self): self.json_utils = JsonUtils() self.file_utils = FileUtils() self.data_merger = DataMerger() def create(self, param): json = self.__build_json(param) path = self.__build_path(param) self.__save(json, path) def __build_json(self, param): return self.data_merger.merge(param) def __build_path(self, param): if 'path' in param: return param['path'] else: relative_path = '''{key}.json'''.format(key=param['stock_symbol']) return self.file_utils.join_paths(param['base_path'], relative_path) def __save(self, json, path): self.json_utils.save(json, path)