-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
118 lines (94 loc) · 3.41 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import time
import glob
import os
import json
# 주소 파일 오류 확인
class NoAddressFileError(Exception):
pass
class TooManyAddressFilesError(Exception):
pass
def handle_dialog(dialog):
"""
:param dialog: 브라우저의 알림창 (confirm / alter 두 종류)
"""
dt = dialog.type
alert_message = dialog.message
if alert_message == "결제카드를 재검증 해주시기 바랍니다.":
pass
else:
print(f"{dt} message: \n{alert_message}")
dialog.accept()
time.sleep(1)
def login_and_cache(context, page, file):
"""
수동으로 로그인하고 cache 파일 저장
"""
page.click("#loginSURL")
# 수동 로그인 20초
time.sleep(20)
# 20초 후 로그인 캐시 저장
context.storage_state(path=file)
print("로그인 정보가 저장되었습니다.")
def find_file():
"""
주소 파일 찾는 함수
:return: .xls or .xlsx 엑셀 파일 하나
"""
xls_files = glob.glob("*.xls") + glob.glob("*.xlsx")
if not xls_files:
print(".xls 또는 .xlsx 형식의 파일을 찾지 못했습니다.")
time.sleep(99999)
if len(xls_files) > 1:
print(".xls 또는 .xlsx 파일이 하나 이상 존재합니다.")
time.sleep(99999)
file_to_upload = xls_files[0]
return file_to_upload
def card_isvalid():
card_number = input("카드 번호를 입력하세요: ").strip()
if len(card_number) != 16:
print("입력하신 카드 번호가 16자리가 아닙니다. \n")
return card_isvalid()
else:
return card_number[:4], card_number[4:8], card_number[8:12], card_number[12:16]
def card_month_year():
card_month = input("카드 유효 기간을 입력하세요 ex) 08/27: ").strip()
if len(card_month) != 5:
print("카드 유효 기간을 잘못 입력하였습니다. 다시 입력해주세요. \n")
return card_month_year()
else:
month, year = card_month.split("/")
return month, year
def card_password():
pwd = input("카드 비밀번호 앞 두 자리를 입력하세요: ").strip()
if len(pwd) != 2:
print("카드 비밀번호 앞 두 자리를 잘못 입력하였습니다. 다시 입력해주세요. \n")
return card_password()
else:
return pwd[0], pwd[1]
def birthdate():
bd = input("카드 소유자 생년월일을 입력하세요 ex) 890403: ")
if len(bd) != 6:
print("카드 소유자 생년월일을 잘못 입력하였습니다. 다시 입력해주세요. \n")
return birthdate()
else:
return bd
def load_card_info(card_info_file):
"""json 형식의 카드 정보 출력"""
if os.path.exists(card_info_file):
with open(card_info_file, "r") as file:
saved_card = json.load(file)
print("현재 사용 중인 카드 정보: ")
keys = ["card1", "card2", "card3", "card4"]
card_number, expire_date = "", ""
for key in keys:
card_number += saved_card[key]
expire_date = f"{saved_card['month']}/{saved_card['year']}"
print(f"저장된 카드 번호: {card_number}")
print(f"저장된 카드 유효기간: {expire_date}")
return saved_card
else:
return None
def save_card_info(card_info_file, card_info):
"""json 형식으로 카드 정보 저장"""
with open(card_info_file, "w") as file:
json.dump(card_info, file)