import os import re class ImageRecovery: def __init__(self): # self.logger = logger self.log_files = ["appTranslator.log.1", "appTranslator.log.2", "appTranslator.log.3", "appTranslator.log.4", "appTranslator.log.5"] def deleted_img_urls_from_logs(self): """로그 파일에서 상품명과 이미지 URL 목록을 추출하여 딕셔너리로 반환하는 메서드""" image_data = {} log_dir = os.path.join(os.path.dirname(__file__)) # 로그 파일에서 필요한 정보만 추출 for log_file in self.log_files: log_path = os.path.join(log_dir, log_file) if os.path.exists(log_path): with open(log_path, 'r', encoding='utf-8') as f: lines = f.readlines() current_product = None for line in lines: # 상품명 추출 product_match = re.search(r"원본 상품명 '(.+?)'", line) if product_match: current_product = product_match.group(1) image_data[current_product] = [] # 이미지 URL 목록 추출 url_match = re.search(r"fetch_image_urls 에서 추출한 이미지URL 목록 : \[(.+?)\]", line) if url_match and current_product: urls = url_match.group(1).split(", ") image_data[current_product].extend(urls) current_product = None # Reset after each product's URL extraction print(f"복구된 이미지 URL 데이터: {image_data}") return image_data if __name__ == "__main__": rv = ImageRecovery() rv.deleted_img_urls_from_logs()