def path(self): old_path = os.path.join(util.storage_path(), self.old_name + ".json") if self.new_name is None: new_path = None else: new_path = os.path.join(util.storage_path(), self.new_name + ".json") return old_path, new_path
def add(self): path = os.path.join(util.storage_path(), self.name + ".json") now = datetime.datetime.now() data = { "name": self.name, "url": self.url, "create_time": now, "update_time": now, "update_times": 0, } with open(path, "w") as page_file: page_file.write(json.dumps(data, cls=PageEncoder, indent=4)) self.logger.info("add page %s successfully" % self.name)
def get_pages_simple_message(self): name_list = os.listdir(util.storage_path()) thread_list = [] for name in name_list: if not util.is_json_file(name): continue thread = threading.Thread( target=self._get_simple_message, args=(name, ), ) thread.start() thread_list.append(thread) for thread in thread_list: thread.join()
def open(self): path = util.path_join(util.storage_path(), self.name + ".json") with open(path, "r") as file: data = json.load(file) webbrowser.open(data["url"]) self.logger.info("open page %s finished." % self.name)
def get_details(self): path = util.path_join(util.storage_path(), self.name + ".json") with open(path, "r") as file: data = json.load(file) self.details = data
def _get_simple_message(self, page_name): path = util.path_join(util.storage_path(), page_name) with open(path, "r") as page_file: data = json.load(page_file) url = data["url"] self.pages[page_name.replace(".json", "")] = url