| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- from typing import List
- from excel_processor import ExcelProcessor
- from translation_service import TranslationService
- from mylib.logging_config import setup_logging
- import logging
- # Setup logging
- setup_logging()
- logger = logging.getLogger('main')
- def process_excel_file(input_path: str, output_path: str, columns_to_translate: List[str]):
- """Main function to process Excel file"""
- try:
- logger.info("Starting Excel processing")
-
- # Initialize services
- excel_processor = ExcelProcessor(input_path)
- translation_service = TranslationService()
- # Process each column
- for column in columns_to_translate:
- # Get unique values for translation
- unique_values = excel_processor.df[column].unique().tolist()
-
- # Translate values
- translations = translation_service.translate_batch(unique_values)
-
- # Add translated column
- excel_processor.add_translation_column(column, translations)
-
- # Add hyperlink column
- if column == "搜索词":
- excel_processor.add_hyperlink_column(column, "https://www.amazon.co.jp/s?k=")
- elif column == "ASIN":
- excel_processor.add_hyperlink_column(column, "https://www.amazon.co.jp/dp/")
- # Save processed file
- excel_processor.save(output_path)
- logger.info("Excel processing completed successfully")
-
- except Exception as e:
- logger.error(f"Error processing Excel file: {str(e)}")
- raise
- if __name__ == "__main__":
- # Example usage
- process_excel_file(
- input_path="input.xlsx",
- output_path="output.xlsx",
- columns_to_translate=["搜索词", "品牌", "点击量最高的类别"]
- )
|