This commit is contained in:
Envy_PC 2025-02-07 17:40:16 +09:00
parent 0765a07066
commit c41b8a20c1
5 changed files with 1420 additions and 1121 deletions

6
gui.py
View File

@ -4,7 +4,7 @@ from toggleSwitch import ToggleSwitch
from browser_control import BrowserController
# from whale_translator import WhaleTranslator
# from vertexAI import VertexAITranslator
from locatorManager import LocatorManager
from locatorManager_by_SP import LocatorManager
from src.cmb_diag import CMBSettingsDialog
from src.DatabaseManager import DatabaseManager
from loggerModule import Logger # 추가
@ -15,7 +15,7 @@ import asyncio
from src.keyword_manager import KeywordManager
from src.kwDBManager_with_sp import KeywordDBManager
from src.kiprisAPI import Kipris_API
from src.sp_manager import SupabaseManager
# from src.sp_manager import SupabaseManager
from user_manual_dialog import UserManualDialog
import configparser
@ -48,7 +48,7 @@ class AutoPercentyGUI(QWidget):
self.debug = False
self.settings = QSettings("WhenRideMycar", "AutoPercenty3") # QSettings 초기화
self.locator_manager = LocatorManager()
self.locator_manager = LocatorManager(self.supabase_manager)
# self.vertexAI = VertexAITranslator(self.logger)
# DB 파일 경로 설정

File diff suppressed because it is too large Load Diff

138
locatorManager_by_SP.py Normal file
View File

@ -0,0 +1,138 @@
import configparser
import os, sys
from supabase import create_client, Client # Supabase Python 클라이언트를 사용한다고 가정
class LocatorManager:
def __init__(self, supabase_manager=None):
"""
supabase_manager가 전달되면, 해당 객체의 client를 이용해 Supabase의 locator 테이블에서 데이터를 가져옵니다.
전달되지 않으면, 기존 config.ini 파일을 로드합니다.
"""
self.base_dir = self.get_base_dir()
self.initial_config_file_path = os.path.join(self.base_dir, "config.ini")
self.config_file = self.initial_config_file_path
self.selectors = {}
self.config = configparser.ConfigParser()
self.supabase_manager = supabase_manager # SupabaseManager 인스턴스 (client 속성이 있어야 함)
if self.supabase_manager is not None:
self.load_locators_from_supabase()
else:
self.load_locators_from_config()
def get_base_dir(self):
"""
실행 환경에 따라 base_dir을 설정하는 메서드.
cx_Freeze로 패키징된 경우 실행 파일의 경로, 일반 Python 환경일 경우 __file__을 기준으로 설정.
"""
if getattr(sys, 'frozen', False): # 패키징된 경우
base_dir = os.path.dirname(sys.executable)
internal_dir = os.path.join(base_dir, '_internal') # _internal 디렉토리 포함
if os.path.exists(internal_dir): # _internal 디렉토리가 존재하면 base_dir로 설정
return internal_dir
else: # 일반 Python 실행 환경
base_dir = os.path.dirname(os.path.abspath(__file__))
return base_dir
def load_locators_from_config(self):
"""
기존 config.ini 파일에서 선택자를 불러와 self.selectors에 저장하는 메서드.
"""
with open(self.config_file, 'r', encoding='utf-8') as config_file:
self.config.read_file(config_file)
# PriceLocators 섹션
self.selectors['PriceLocators'] = {
'return_fee_input_locator': self.config.get('PriceLocators', 'return_fee_input_locator').strip("'"),
'first_delv_fee_input_locator': self.config.get('PriceLocators', 'first_delv_fee_input_locator').strip("'"),
'exchange_fee_input_locator': self.config.get('PriceLocators', 'exchange_fee_input_locator').strip("'"),
'plus_margin_locator': self.config.get('PriceLocators', 'plus_margin_locator').strip("'"),
'oversea_shipping_locator': self.config.get('PriceLocators', 'oversea_shipping_locator').strip("'"),
'option_count_text_locator': self.config.get('PriceLocators', 'option_count_text_locator').strip("'"),
'product_cost_locator': self.config.get('PriceLocators', 'product_cost_locator').strip("'"),
'standard_selling_price_locator': self.config.get('PriceLocators', 'standard_selling_price_locator').strip("'"),
'product_cost_for_group_locator': self.config.get('PriceLocators', 'product_cost_for_group_locator').strip("'"),
'standard_selling_price_for_group_locator': self.config.get('PriceLocators', 'standard_selling_price_for_group_locator').strip("'"),
'product_cost_for_single_locator': self.config.get('PriceLocators', 'product_cost_for_single_locator').strip("'"),
'standard_selling_price_for_single_locator': self.config.get('PriceLocators', 'standard_selling_price_for_single_locator').strip("'"),
'ordering_by_name_locator': self.config.get('PriceLocators', 'ordering_by_name_locator').strip("'"),
'ordering_by_option_locator': self.config.get('PriceLocators', 'ordering_by_option_locator').strip("'"),
}
# TagsLocators 섹션
self.selectors['TagsLocators'] = {
'tags_input_locator': self.config.get('TagsLocators', 'tags_input_locator').strip("'"),
'tags_input_Button_locator': self.config.get('TagsLocators', 'tags_input_Button_locator').strip("'"),
'delete_warning_tags_button_locator': self.config.get('TagsLocators', 'delete_warning_tags_button_locator').strip("'"),
'tags_input_locator_for_xpath': self.config.get('TagsLocators', 'tags_input_locator').strip("'"),
'tags_input_Button_locator_for_xpath': self.config.get('TagsLocators', 'tags_input_Button_locator').strip("'"),
'delete_warning_tags_button_locator_for_xpath': self.config.get('TagsLocators', 'delete_warning_tags_button_locator').strip("'"),
}
# BrowserControl 섹션
self.selectors['BrowserControl'] = {
'login_email_locator': self.config.get('BrowserControl', 'login_email_locator').strip("'"),
'login_password_locator': self.config.get('BrowserControl', 'login_password_locator').strip("'"),
# ... (기타 BrowserControl 관련 선택자)
}
# DetailPageTextTemplates 섹션
self.selectors['DetailPageTextTemplates'] = {
key: value.strip("'") for key, value in self.config.items('DetailPageTextTemplates')
}
# OptionLocators 섹션
self.selectors['OptionLocators'] = {
'option_excluded_selector_template': self.config.get('OptionLocators', 'option_excluded_selector_template').strip("'"),
'option_input_selector_template': self.config.get('OptionLocators', 'option_input_selector_template').strip("'"),
# ... (기타 OptionLocators 관련 선택자)
}
# TitleLocators 섹션
self.selectors['TitleLocators'] = {
'product_name_input_locator': self.config.get('TitleLocators', 'product_name_input_locator').strip("'"),
'product_name_suggestion_input_locator': self.config.get('TitleLocators', 'product_name_suggestion_input_locator').strip("'"),
# ... (기타 TitleLocators 관련 선택자)
}
def load_locators_from_supabase(self):
"""
Supabase의 locator 테이블에서 선택자 정보를 조회하여 self.selectors에 저장합니다.
테이블 'locators' 행마다 section, key, value 컬럼을 가진다고 가정합니다.
"""
try:
# SupabaseManager의 client를 사용합니다.
response = self.supabase_manager.client.table("locators").select("*").execute()
if response.data:
for row in response.data:
section = row.get("section")
key = row.get("key")
value = row.get("value")
if section not in self.selectors:
self.selectors[section] = {}
self.selectors[section][key] = value
print("Supabase에서 로케이터 데이터를 성공적으로 로드하였습니다.")
else:
print("Supabase locator 테이블에 데이터가 없습니다. 기존 config.ini를 사용합니다.")
self.load_locators_from_config()
except Exception as e:
print(f"Supabase에서 locator 데이터를 가져오는 중 오류 발생: {e}")
print("기존 config.ini를 사용합니다.")
self.load_locators_from_config()
def get_locator(self, section, key):
"""
섹션과 키를 받아서 해당 선택자를 반환합니다.
"""
return self.selectors.get(section, {}).get(key, None)
def get_category_data(self, section, category):
"""
Config.ini 또는 Supabase에서 특정 카테고리에 대한 데이터를 반환하는 메서드.
"""
try:
category_data = self.config[section][category]
return category_data
except KeyError:
print(f"{section} 섹션에서 {category} 카테고리를 찾을 수 없습니다.")
return None

View File

@ -3,7 +3,8 @@ import ctypes
from PySide6.QtWidgets import QApplication
from sleep_control import prevent_sleep_mode, restore_sleep_mode
from login_dialog import LoginDialog
from gui import AutoPercentyGUI
#from gui import AutoPercentyGUI
from mainUI_SP import AutoPercentyGUI
from limited_gui import AutoPercentyLimitedGUI
# Windows DPI Awareness Constants

1277
mainUI_SP.py Normal file

File diff suppressed because it is too large Load Diff