mirror of
https://github.com/NanmiCoder/MediaCrawler.git
synced 2026-06-08 10:57:26 +08:00
fix(store): 修复存储实现的AsyncFileWriter导入
重构小红书存储实现,将store_comments方法改为处理单个评论的store_comment 为多个平台添加AsyncFileWriter工具类导入
This commit is contained in:
@@ -19,6 +19,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
from tools.async_file_writer import AsyncFileWriter
|
||||||
|
|
||||||
import aiofiles
|
import aiofiles
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ from database.models import TiebaNote, TiebaComment, TiebaCreator
|
|||||||
from tools import utils, words
|
from tools import utils, words
|
||||||
from database.db_session import get_session
|
from database.db_session import get_session
|
||||||
from var import crawler_type_var
|
from var import crawler_type_var
|
||||||
|
from tools.async_file_writer import AsyncFileWriter
|
||||||
|
|
||||||
|
|
||||||
def calculate_number_of_files(file_store_path: str) -> int:
|
def calculate_number_of_files(file_store_path: str) -> int:
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import config
|
|||||||
from base.base_crawler import AbstractStore
|
from base.base_crawler import AbstractStore
|
||||||
from database.models import WeiboCreator, WeiboNote, WeiboNoteComment
|
from database.models import WeiboCreator, WeiboNote, WeiboNoteComment
|
||||||
from tools import utils, words
|
from tools import utils, words
|
||||||
|
from tools.async_file_writer import AsyncFileWriter
|
||||||
from database.db_session import get_session
|
from database.db_session import get_session
|
||||||
from var import crawler_type_var
|
from var import crawler_type_var
|
||||||
|
|
||||||
|
|||||||
@@ -32,14 +32,13 @@ class XhsCsvStoreImplement(AbstractStore):
|
|||||||
"""
|
"""
|
||||||
await self.writer.write_to_csv(item_type="contents", item=content_item)
|
await self.writer.write_to_csv(item_type="contents", item=content_item)
|
||||||
|
|
||||||
async def store_comments(self, comments: List[Dict]):
|
async def store_comment(self, comment_item: Dict):
|
||||||
"""
|
"""
|
||||||
store comments data to csv file
|
store comment data to csv file
|
||||||
:param comments:
|
:param comment_item:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
for comment in comments:
|
await self.writer.write_to_csv(item_type="comments", item=comment_item)
|
||||||
await self.writer.write_to_csv(item_type="comments", item=comment)
|
|
||||||
|
|
||||||
|
|
||||||
async def store_creator(self, creator_item: Dict):
|
async def store_creator(self, creator_item: Dict):
|
||||||
@@ -62,14 +61,13 @@ class XhsJsonStoreImplement(AbstractStore):
|
|||||||
"""
|
"""
|
||||||
await self.writer.write_single_item_to_json(item_type="contents", item=content_item)
|
await self.writer.write_single_item_to_json(item_type="contents", item=content_item)
|
||||||
|
|
||||||
async def store_comments(self, comments: List[Dict]):
|
async def store_comment(self, comment_item: Dict):
|
||||||
"""
|
"""
|
||||||
store comments data to json file
|
store comment data to json file
|
||||||
:param comments:
|
:param comment_item:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
for comment in comments:
|
await self.writer.write_single_item_to_json(item_type="comments", item=comment_item)
|
||||||
await self.writer.write_single_item_to_json(item_type="comments", item=comment)
|
|
||||||
|
|
||||||
async def store_creator(self, creator_item: Dict):
|
async def store_creator(self, creator_item: Dict):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ from database.db_session import get_session
|
|||||||
from database.models import ZhihuContent, ZhihuComment, ZhihuCreator
|
from database.models import ZhihuContent, ZhihuComment, ZhihuCreator
|
||||||
from tools import utils, words
|
from tools import utils, words
|
||||||
from var import crawler_type_var
|
from var import crawler_type_var
|
||||||
|
from tools.async_file_writer import AsyncFileWriter
|
||||||
|
|
||||||
def calculate_number_of_files(file_store_path: str) -> int:
|
def calculate_number_of_files(file_store_path: str) -> int:
|
||||||
"""计算数据保存文件的前部分排序数字,支持每次运行代码不写到同一个文件中
|
"""计算数据保存文件的前部分排序数字,支持每次运行代码不写到同一个文件中
|
||||||
|
|||||||
Reference in New Issue
Block a user