Pushbutton connect
This commit is contained in:
parent
0fad651c1e
commit
4f7fd9c20b
|
|
@ -0,0 +1,6 @@
|
||||||
|
pyqt5
|
||||||
|
asyncqt
|
||||||
|
playwright
|
||||||
|
cryptography
|
||||||
|
loguru
|
||||||
|
pyperclip
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton, QHBoxLayout
|
||||||
|
import pyperclip
|
||||||
|
|
||||||
|
class ApiKeyWidget(QWidget):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.setWindowTitle("API Keys")
|
||||||
|
self.setGeometry(100, 100, 400, 400)
|
||||||
|
|
||||||
|
self.layout = QVBoxLayout()
|
||||||
|
self.setLayout(self.layout)
|
||||||
|
|
||||||
|
# 초기화된 UI 구성 요소를 저장할 리스트
|
||||||
|
self.key_widgets = []
|
||||||
|
|
||||||
|
# 확인 버튼 추가 및 초기화
|
||||||
|
self.confirm_button = QPushButton("확인")
|
||||||
|
self.confirm_button.clicked.connect(self.close)
|
||||||
|
self.layout.addWidget(self.confirm_button)
|
||||||
|
|
||||||
|
def call_UI(self, api_keys):
|
||||||
|
# 기존 위젯 제거
|
||||||
|
self.clear_layout()
|
||||||
|
|
||||||
|
if api_keys:
|
||||||
|
for key, value in api_keys.items():
|
||||||
|
h_layout = QHBoxLayout()
|
||||||
|
|
||||||
|
key_label = QLabel(f"키 이름: {key}")
|
||||||
|
value_label = QLabel(f"키 값: {value}")
|
||||||
|
copy_button = QPushButton("키 복사")
|
||||||
|
|
||||||
|
copy_button.clicked.connect(lambda checked, v=value: self.copy_to_clipboard(v))
|
||||||
|
|
||||||
|
h_layout.addWidget(key_label)
|
||||||
|
h_layout.addWidget(value_label)
|
||||||
|
h_layout.addWidget(copy_button)
|
||||||
|
|
||||||
|
self.layout.insertLayout(self.layout.count() - 1, h_layout)
|
||||||
|
self.key_widgets.append((key_label, value_label, copy_button))
|
||||||
|
|
||||||
|
self.show()
|
||||||
|
|
||||||
|
def clear_layout(self):
|
||||||
|
for widgets in self.key_widgets:
|
||||||
|
for widget in widgets:
|
||||||
|
widget.deleteLater()
|
||||||
|
self.key_widgets.clear()
|
||||||
|
|
||||||
|
def copy_to_clipboard(self, value):
|
||||||
|
pyperclip.copy(value)
|
||||||
|
print(f"Copied to clipboard: {value}")
|
||||||
|
|
@ -5,14 +5,17 @@ from ui.business_settings import BusinessSettingsDialog
|
||||||
from ui.help_dialog import HelpDialog
|
from ui.help_dialog import HelpDialog
|
||||||
from utils.playwright_helpers import PlaywrightHelper
|
from utils.playwright_helpers import PlaywrightHelper
|
||||||
from utils.config import ConfigManager
|
from utils.config import ConfigManager
|
||||||
import asyncio
|
import asyncio, pyperclip
|
||||||
|
from ui.apikey_widget import ApiKeyWidget
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
def __init__(self, config, logger):
|
def __init__(self, config, logger):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.config = config
|
self.config = config
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
|
self.current_api_keys = {}
|
||||||
self.playwright_helper = PlaywrightHelper()
|
self.playwright_helper = PlaywrightHelper()
|
||||||
|
self.api_widget = ApiKeyWidget()
|
||||||
|
|
||||||
self.setWindowTitle('Change-Percenty2')
|
self.setWindowTitle('Change-Percenty2')
|
||||||
self.setGeometry(100, 100, 450, 800)
|
self.setGeometry(100, 100, 450, 800)
|
||||||
|
|
@ -186,6 +189,14 @@ class MainWindow(QMainWindow):
|
||||||
self.market_info_at_label = QLabel('------')
|
self.market_info_at_label = QLabel('------')
|
||||||
|
|
||||||
self.market_info_cc_btn.clicked.connect(lambda: self.market_info_cc_btn_clicked(self.market_info_cc_btn))
|
self.market_info_cc_btn.clicked.connect(lambda: self.market_info_cc_btn_clicked(self.market_info_cc_btn))
|
||||||
|
self.market_info_ss_btn.clicked.connect(lambda: self.market_info_cc_btn_clicked(self.market_info_ss_btn))
|
||||||
|
self.market_info_dm11_btn.clicked.connect(lambda: self.market_info_cc_btn_clicked(self.market_info_dm11_btn))
|
||||||
|
self.market_info_gb11_btn.clicked.connect(lambda: self.market_info_cc_btn_clicked(self.market_info_gb11_btn))
|
||||||
|
self.market_info_esm_btn.clicked.connect(lambda: self.market_info_cc_btn_clicked(self.market_info_esm_btn))
|
||||||
|
self.market_info_lton_btn.clicked.connect(lambda: self.market_info_cc_btn_clicked(self.market_info_lton_btn))
|
||||||
|
self.market_info_ip_btn.clicked.connect(lambda: self.market_info_cc_btn_clicked(self.market_info_ip_btn))
|
||||||
|
self.market_info_wmp_btn.clicked.connect(lambda: self.market_info_cc_btn_clicked(self.market_info_wmp_btn))
|
||||||
|
self.market_info_at_btn.clicked.connect(lambda: self.market_info_cc_btn_clicked(self.market_info_at_btn))
|
||||||
|
|
||||||
|
|
||||||
self.market_info_box.addWidget(self.market_info_label,1,1,1,2)
|
self.market_info_box.addWidget(self.market_info_label,1,1,1,2)
|
||||||
|
|
@ -290,8 +301,14 @@ class MainWindow(QMainWindow):
|
||||||
self.at_checkbox.setChecked(False)
|
self.at_checkbox.setChecked(False)
|
||||||
|
|
||||||
def market_info_cc_btn_clicked(self, button):
|
def market_info_cc_btn_clicked(self, button):
|
||||||
print(f"button 클릭됨 : {button}")
|
currentBtnMarket = button.text()
|
||||||
# self.label.setText(f'{button.text()} clicked')
|
if self.current_api_keys:
|
||||||
|
print("get_market_infos 호출")
|
||||||
|
market_api_infos = self.get_market_infos(self.current_api_keys, currentBtnMarket)
|
||||||
|
print("call_UI")
|
||||||
|
self.api_widget.call_UI(market_api_infos)
|
||||||
|
else:
|
||||||
|
print(f"{currentBtnMarket}의 마켓정보 없음")
|
||||||
|
|
||||||
async def fetch_settings(self):
|
async def fetch_settings(self):
|
||||||
self.logger.debug("Fetching settings...")
|
self.logger.debug("Fetching settings...")
|
||||||
|
|
@ -303,18 +320,19 @@ class MainWindow(QMainWindow):
|
||||||
user_id = self.config.get('USER', 'user_id')
|
user_id = self.config.get('USER', 'user_id')
|
||||||
password = self.config.decrypt(self.config.get('USER', 'password'))
|
password = self.config.decrypt(self.config.get('USER', 'password'))
|
||||||
|
|
||||||
api_keys = await self.playwright_helper.login_and_fetch_api_keys('https://percenty.co.kr', user_id, password, self.status_label, self.progress_bar)
|
web_api_keys = await self.playwright_helper.login_and_fetch_api_keys('https://percenty.co.kr', user_id, password, self.status_label, self.progress_bar)
|
||||||
print(f"가져온 apikeys\n{api_keys}")
|
self.current_api_keys = web_api_keys
|
||||||
|
print(f"가져온 apikeys\n{web_api_keys}")
|
||||||
|
|
||||||
business_info = self.search_apikeys(api_keys)
|
business_info = self.search_apikeys_for_business(web_api_keys)
|
||||||
|
|
||||||
# 가져온 API 키를 UI에 업데이트하는 로직 추가
|
# 가져온 API 키를 UI에 업데이트하는 로직 추가
|
||||||
self.update_market_info(api_keys, business_info)
|
self.update_market_info(web_api_keys, business_info)
|
||||||
self.progress_bar.setValue(100)
|
self.progress_bar.setValue(100)
|
||||||
self.status_label.setText('현재 상태: 설정 가져오기 완료')
|
self.status_label.setText('현재 상태: 설정 가져오기 완료')
|
||||||
await self.playwright_helper.close_browser()
|
await self.playwright_helper.close_browser()
|
||||||
|
|
||||||
def search_apikeys(self, api_keys):
|
def search_apikeys_for_business(self, api_keys):
|
||||||
self.status_label.setText('현재 상태: 키 검증하기')
|
self.status_label.setText('현재 상태: 키 검증하기')
|
||||||
|
|
||||||
business_info = {
|
business_info = {
|
||||||
|
|
@ -328,7 +346,7 @@ class MainWindow(QMainWindow):
|
||||||
# max_business = int(self.config.get('DEFAULT', 'max_businesses'))
|
# max_business = int(self.config.get('DEFAULT', 'max_businesses'))
|
||||||
|
|
||||||
all = self.config.get_all_businesses()
|
all = self.config.get_all_businesses()
|
||||||
print(f"사업자 수 : {len(all)}")
|
print(f"저장된 사업자 수 : [{len(all)}] 개")
|
||||||
print(f"all : {all}")
|
print(f"all : {all}")
|
||||||
|
|
||||||
progress_step = 15 / len(all)
|
progress_step = 15 / len(all)
|
||||||
|
|
@ -337,7 +355,6 @@ class MainWindow(QMainWindow):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 저장된 모든 사업자 정보 가져오기
|
# 저장된 모든 사업자 정보 가져오기
|
||||||
|
|
||||||
for business_section in all:
|
for business_section in all:
|
||||||
print(f"키검증 business_section : {business_section}")
|
print(f"키검증 business_section : {business_section}")
|
||||||
stored_api_keys = self.config.get_api_keys(business_section)
|
stored_api_keys = self.config.get_api_keys(business_section)
|
||||||
|
|
@ -359,9 +376,18 @@ class MainWindow(QMainWindow):
|
||||||
print(f"business_info{business_info}")
|
print(f"business_info{business_info}")
|
||||||
return business_info
|
return business_info
|
||||||
|
|
||||||
|
def get_market_infos(self, current_api_keys, market_name):
|
||||||
|
# 현재 current_api_keys는 이미 전체 마켓 데이터를 포함하는 사전입니다.
|
||||||
|
if market_name in current_api_keys:
|
||||||
|
market_details = current_api_keys[market_name]
|
||||||
|
api_keys = {key: value for key, value in market_details.items() if 'key' in key.lower() or '키' in key}
|
||||||
|
return api_keys
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def update_market_info(self, api_keys, business_info):
|
def update_market_info(self, api_keys, business_info):
|
||||||
print(f"update_market_info : {api_keys}, {business_info}")
|
print(f"update_market_info : {api_keys}\n\n{business_info}")
|
||||||
|
|
||||||
# 사업자 정보 업데이트
|
# 사업자 정보 업데이트
|
||||||
self.business_info_label_context.setText(business_info['사업자별칭'])
|
self.business_info_label_context.setText(business_info['사업자별칭'])
|
||||||
|
|
|
||||||
|
|
@ -30,17 +30,21 @@ class PlaywrightHelper:
|
||||||
progress_bar.setValue(20)
|
progress_bar.setValue(20)
|
||||||
status_label.setText('현재 상태: 퍼센티 로그인 완료')
|
status_label.setText('현재 상태: 퍼센티 로그인 완료')
|
||||||
|
|
||||||
|
|
||||||
# 팝업 다이얼로그 닫기 (있는 경우)
|
|
||||||
try:
|
|
||||||
await page.click("xpath=body > div:nth-child(10) > div > div.ant-modal-wrap.ant-modal-centered > div > div.ant-modal-content > div.ant-modal-footer > button.ant-btn.css-1li46mu.ant-btn-primary")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# 마켓 설정 페이지로 이동
|
# 마켓 설정 페이지로 이동
|
||||||
await page.click("xpath=/html/body/div[1]/div/div/div/div/aside/div/ul/li[7]/ul/li[2]")
|
await page.click("xpath=/html/body/div[1]/div/div/div/div/aside/div/ul/li[7]/ul/li[2]")
|
||||||
# await page.click("div#root li.ant-menu-item.ant-menu-item-selected.ant-menu-item-only-child > span")
|
# await page.click("div#root li.ant-menu-item.ant-menu-item-selected.ant-menu-item-only-child > span")
|
||||||
|
|
||||||
|
# 마켓 설정상 팝업 다이얼로그가 있는 경우 닫기 (있는 경우)
|
||||||
|
try:
|
||||||
|
# await page.click(".ant-modal-footer [type='button']")
|
||||||
|
await page.click("div.ant-modal-footer > button[type=\"button\"].ant-btn.css-1li46mu.ant-btn-primary")
|
||||||
|
|
||||||
|
# .ant-modal-content
|
||||||
|
# .ant-modal-footer [type='button']
|
||||||
|
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
progress_bar.setValue(30)
|
progress_bar.setValue(30)
|
||||||
status_label.setText('현재 상태: 마켓 설정')
|
status_label.setText('현재 상태: 마켓 설정')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue