|
@@ -1,3 +1,4 @@
|
|
|
|
|
+import asyncio
|
|
|
import json
|
|
import json
|
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
|
import shutil
|
|
import shutil
|
|
@@ -13,7 +14,8 @@ from src.manager import DbManager,StorageManager
|
|
|
from utils.logu import get_logger
|
|
from utils.logu import get_logger
|
|
|
from config.settings import OUTPUT_DIR
|
|
from config.settings import OUTPUT_DIR
|
|
|
from src.models.asin_model import AsinExtraResultModel
|
|
from src.models.asin_model import AsinExtraResultModel
|
|
|
-
|
|
|
|
|
|
|
+from src.models.product_model import Product,CompetitorAnalysis
|
|
|
|
|
+from src.manager.core.db_mongo import BaseMongoManager
|
|
|
|
|
|
|
|
logger = get_logger('excel')
|
|
logger = get_logger('excel')
|
|
|
|
|
|
|
@@ -40,25 +42,22 @@ class ExcelFileManager:
|
|
|
self.wb.save(self.output_path)
|
|
self.wb.save(self.output_path)
|
|
|
self.wb.close()
|
|
self.wb.close()
|
|
|
|
|
|
|
|
- def write_competitive_sheet(self, extract_data:dict, sheet_name: str = "竞品关键词调研", sheet_index: int = 0, overwrite: bool = False):
|
|
|
|
|
|
|
+ def write_competitive_sheet(self, competitor_analysis:Dict[str, CompetitorAnalysis], sheet_name: str = "竞品关键词调研", sheet_index: int = 0, overwrite: bool = False):
|
|
|
if overwrite and sheet_name in self.wb.sheetnames:
|
|
if overwrite and sheet_name in self.wb.sheetnames:
|
|
|
self.wb.remove(self.wb[sheet_name])
|
|
self.wb.remove(self.wb[sheet_name])
|
|
|
if sheet_name not in self.wb.sheetnames:
|
|
if sheet_name not in self.wb.sheetnames:
|
|
|
competitive_sheet_writer = CompetitiveAnalysisWriter(self.wb, sheet_name=sheet_name, sheet_index=sheet_index)
|
|
competitive_sheet_writer = CompetitiveAnalysisWriter(self.wb, sheet_name=sheet_name, sheet_index=sheet_index)
|
|
|
- competitive_sheet_writer.add_data(extract_data)
|
|
|
|
|
|
|
+ competitive_sheet_writer.add_data(competitor_analysis)
|
|
|
def load_s3_extract_data(self) -> list[AsinExtraResultModel]:
|
|
def load_s3_extract_data(self) -> list[AsinExtraResultModel]:
|
|
|
return self.s3_storage_manager.load_s3_complete_extract_data()
|
|
return self.s3_storage_manager.load_s3_complete_extract_data()
|
|
|
|
|
|
|
|
-def main():
|
|
|
|
|
|
|
+async def main():
|
|
|
self = ExcelFileManager(r"G:\code\amazone\copywriting_production\output\resource\multi_data.xlsx")
|
|
self = ExcelFileManager(r"G:\code\amazone\copywriting_production\output\resource\multi_data.xlsx")
|
|
|
- extract_data_lsit = self.load_s3_extract_data()
|
|
|
|
|
- logger.info(f"{extract_data_lsit}")
|
|
|
|
|
- dict_list = [model.model_dump() for model in extract_data_lsit]
|
|
|
|
|
- # 使用 json.dumps() 将字典列表转换为 JSON 字符串
|
|
|
|
|
- json_str = json.dumps(dict_list, indent=4, ensure_ascii=False)
|
|
|
|
|
- save_to_file(json_str, OUTPUT_DIR / "multi_data.json")
|
|
|
|
|
- logger.info(f"{len(extract_data_lsit)}")
|
|
|
|
|
- # self.write_competie_sheet(extract_data)
|
|
|
|
|
|
|
+ db_mongo = BaseMongoManager()
|
|
|
|
|
+ asyncio.run(db_mongo.initialize())
|
|
|
|
|
+ product = await Product.find_one(Product.basic_info.name == "电线保护套")
|
|
|
|
|
+ extract_data_lsit = product.competitor_analysis
|
|
|
|
|
+ self.write_competitive_sheet(product.competitor_analysis)
|
|
|
# self.save_all()
|
|
# self.save_all()
|
|
|
return
|
|
return
|
|
|
competi_sheet = CompetitiveAnalysisWriter(excel_file.output_path)
|
|
competi_sheet = CompetitiveAnalysisWriter(excel_file.output_path)
|
|
@@ -86,4 +85,4 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
|
- main()
|
|
|
|
|
|
|
+ asyncio.run(main())
|