From 926ea9dc42ee1e0b6a4c90e2680050c91cff0299 Mon Sep 17 00:00:00 2001 From: persist-1 Date: Thu, 11 Sep 2025 00:35:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=88=86=E9=9A=94=E7=AC=A6=E8=BF=9E=E6=8E=A5=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E4=B8=8D=E5=BD=93=E5=AF=BC=E8=87=B4=E7=9A=84=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改'async_file_writer.py'中'_get_file_path'返回值由字符串连接改为直接用正斜杠拼接路径,以确保路径分隔符的统一 - 修改获取文件保存时间后缀方式为'get_current_date',以'天'为文件内容划分点 --- tools/async_file_writer.py | 4 ++-- tools/time_util.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/async_file_writer.py b/tools/async_file_writer.py index f4d430e..972fff8 100644 --- a/tools/async_file_writer.py +++ b/tools/async_file_writer.py @@ -16,8 +16,8 @@ class AsyncFileWriter: def _get_file_path(self, file_type: str, item_type: str) -> str: base_path = f"data/{self.platform}/{file_type}" pathlib.Path(base_path).mkdir(parents=True, exist_ok=True) - file_name = f"{self.crawler_type}_{item_type}_{utils.get_current_time()}.{file_type}" - return os.path.join(base_path, file_name) + file_name = f"{self.crawler_type}_{item_type}_{utils.get_current_date()}.{file_type}" + return f"{base_path}/{file_name}" async def write_to_csv(self, item: Dict, item_type: str): file_path = self._get_file_path('csv', item_type) diff --git a/tools/time_util.py b/tools/time_util.py index 341aa80..d2eed96 100644 --- a/tools/time_util.py +++ b/tools/time_util.py @@ -33,6 +33,12 @@ def get_current_time() -> str: """ return time.strftime('%Y-%m-%d %X', time.localtime()) +def get_current_time_hour() -> str: + """ + 获取当前的时间:'2023-12-02-13' + :return: + """ + return time.strftime('%Y-%m-%d-%H', time.localtime()) def get_current_date() -> str: """