mirror of
https://github.com/NanmiCoder/MediaCrawler.git
synced 2026-06-07 10:27:25 +08:00
fix: 修复路径分隔符连接方式不当导致的路径格式问题
- 修改'async_file_writer.py'中'_get_file_path'返回值由字符串连接改为直接用正斜杠拼接路径,以确保路径分隔符的统一 - 修改获取文件保存时间后缀方式为'get_current_date',以'天'为文件内容划分点
This commit is contained in:
@@ -16,8 +16,8 @@ class AsyncFileWriter:
|
|||||||
def _get_file_path(self, file_type: str, item_type: str) -> str:
|
def _get_file_path(self, file_type: str, item_type: str) -> str:
|
||||||
base_path = f"data/{self.platform}/{file_type}"
|
base_path = f"data/{self.platform}/{file_type}"
|
||||||
pathlib.Path(base_path).mkdir(parents=True, exist_ok=True)
|
pathlib.Path(base_path).mkdir(parents=True, exist_ok=True)
|
||||||
file_name = f"{self.crawler_type}_{item_type}_{utils.get_current_time()}.{file_type}"
|
file_name = f"{self.crawler_type}_{item_type}_{utils.get_current_date()}.{file_type}"
|
||||||
return os.path.join(base_path, file_name)
|
return f"{base_path}/{file_name}"
|
||||||
|
|
||||||
async def write_to_csv(self, item: Dict, item_type: str):
|
async def write_to_csv(self, item: Dict, item_type: str):
|
||||||
file_path = self._get_file_path('csv', item_type)
|
file_path = self._get_file_path('csv', item_type)
|
||||||
|
|||||||
@@ -33,6 +33,12 @@ def get_current_time() -> str:
|
|||||||
"""
|
"""
|
||||||
return time.strftime('%Y-%m-%d %X', time.localtime())
|
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:
|
def get_current_date() -> str:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user