2022-11-09, add keyword#3 and keyword#4

master
CHUN YU YAO 2022-11-10 01:56:12 +08:00
parent 856c667451
commit 24f59119ed
2 changed files with 134 additions and 7 deletions

View File

@ -67,7 +67,7 @@ ssl._create_default_https_context = ssl._create_unverified_context
#附註1沒有寫的很好很多地方應該可以模組化。 #附註1沒有寫的很好很多地方應該可以模組化。
#附註2 #附註2
CONST_APP_VERSION = u"MaxBot (2022.11.08)" CONST_APP_VERSION = u"MaxBot (2022.11.09)"
CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom" CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom"
CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top" CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top"
@ -101,6 +101,8 @@ area_keyword = None
area_keyword_1 = None area_keyword_1 = None
area_keyword_2 = None area_keyword_2 = None
area_keyword_3 = None
area_keyword_4 = None
pass_1_seat_remaining_enable = False # default not checked. pass_1_seat_remaining_enable = False # default not checked.
pass_date_is_sold_out_enable = False # default not checked. pass_date_is_sold_out_enable = False # default not checked.
@ -320,6 +322,8 @@ def load_config_from_local(driver):
global area_keyword_1 global area_keyword_1
global area_keyword_2 global area_keyword_2
global area_keyword_3
global area_keyword_4
global date_auto_select_enable global date_auto_select_enable
global date_auto_select_mode global date_auto_select_mode
@ -423,6 +427,14 @@ def load_config_from_local(driver):
area_keyword_2 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"] area_keyword_2 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"]
area_keyword_2 = area_keyword_2.strip() area_keyword_2 = area_keyword_2.strip()
if 'area_keyword_3' in config_dict["tixcraft"]["area_auto_select"]:
area_keyword_3 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_3"]
area_keyword_3 = area_keyword_3.strip()
if 'area_keyword_4' in config_dict["tixcraft"]["area_auto_select"]:
area_keyword_4 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_4"]
area_keyword_4 = area_keyword_4.strip()
pass_1_seat_remaining_enable = False pass_1_seat_remaining_enable = False
if 'pass_1_seat_remaining' in config_dict["tixcraft"]: if 'pass_1_seat_remaining' in config_dict["tixcraft"]:
pass_1_seat_remaining_enable = config_dict["tixcraft"]["pass_1_seat_remaining"] pass_1_seat_remaining_enable = config_dict["tixcraft"]["pass_1_seat_remaining"]
@ -462,6 +474,8 @@ def load_config_from_local(driver):
print("area_auto_select_mode", area_auto_select_mode) print("area_auto_select_mode", area_auto_select_mode)
print("area_keyword_1", area_keyword_1) print("area_keyword_1", area_keyword_1)
print("area_keyword_2", area_keyword_2) print("area_keyword_2", area_keyword_2)
print("area_keyword_3", area_keyword_3)
print("area_keyword_4", area_keyword_4)
print("pass_1_seat_remaining", pass_1_seat_remaining_enable) print("pass_1_seat_remaining", pass_1_seat_remaining_enable)
print("pass_date_is_sold_out", pass_date_is_sold_out_enable) print("pass_date_is_sold_out", pass_date_is_sold_out_enable)
@ -1140,6 +1154,7 @@ def date_auto_select(driver, url, date_auto_select_mode, date_keyword, pass_date
# RETURN: # RETURN:
# is_need_refresh # is_need_refresh
# areas # areas
# PS: areas will be None, if length equals zero.
def get_tixcraft_target_area(el, area_keyword, area_auto_select_mode, pass_1_seat_remaining_enable): def get_tixcraft_target_area(el, area_keyword, area_auto_select_mode, pass_1_seat_remaining_enable):
debugMode = True debugMode = True
debugMode = False # for online debugMode = False # for online
@ -1195,6 +1210,9 @@ def get_tixcraft_target_area(el, area_keyword, area_auto_select_mode, pass_1_sea
# clean stop word. # clean stop word.
area_keyword = format_keyword_string(area_keyword) area_keyword = format_keyword_string(area_keyword)
# allow only input stop word in keyword fields.
# for keyword#2 to select all.
if len(area_keyword) > 0:
# must match keyword. # must match keyword.
if area_keyword in row_text: if area_keyword in row_text:
is_append_this_row = True is_append_this_row = True
@ -1250,12 +1268,13 @@ def get_tixcraft_target_area(el, area_keyword, area_auto_select_mode, pass_1_sea
# PS: auto refresh condition 1: no keyword + no hyperlink. # PS: auto refresh condition 1: no keyword + no hyperlink.
# PS: auto refresh condition 2: with keyword + no hyperlink. # PS: auto refresh condition 2: with keyword + no hyperlink.
def area_auto_select(driver, url, area_keyword_1, area_keyword_2, area_auto_select_mode, pass_1_seat_remaining_enable): def area_auto_select(driver, url, area_keyword_1, area_keyword_2, area_keyword_3, area_keyword_4, area_auto_select_mode, pass_1_seat_remaining_enable):
debugMode = True debugMode = True
debugMode = False # for online debugMode = False # for online
if debugMode: if debugMode:
print("area_keyword_1, area_keyword_2:", area_keyword_1, area_keyword_2) print("area_keyword_1, area_keyword_2:", area_keyword_1, area_keyword_2)
print("area_keyword_3, area_keyword_4:", area_keyword_3, area_keyword_4)
if '/ticket/area/' in url: if '/ticket/area/' in url:
#driver.switch_to.default_content() #driver.switch_to.default_content()
@ -1275,12 +1294,35 @@ def area_auto_select(driver, url, area_keyword_1, area_keyword_2, area_auto_sele
if areas is None: if areas is None:
if debugMode: if debugMode:
print("use area keyword #2", area_keyword_2) print("use area keyword #2", area_keyword_2)
# only when keyword#2 filled to query. # only when keyword#2 filled to query.
if len(area_keyword_2) > 0 : if len(area_keyword_2) > 0 :
is_need_refresh, areas = get_tixcraft_target_area(el, area_keyword_2, area_auto_select_mode, pass_1_seat_remaining_enable) is_need_refresh, areas = get_tixcraft_target_area(el, area_keyword_2, area_auto_select_mode, pass_1_seat_remaining_enable)
if debugMode: if debugMode:
print("is_need_refresh for keyword2:", is_need_refresh) print("is_need_refresh for keyword2:", is_need_refresh)
if is_need_refresh:
if areas is None:
if debugMode:
print("use area keyword #3", area_keyword_3)
# only when keyword#3 filled to query.
if len(area_keyword_3) > 0 :
is_need_refresh, areas = get_tixcraft_target_area(el, area_keyword_3, area_auto_select_mode, pass_1_seat_remaining_enable)
if debugMode:
print("is_need_refresh for keyword3:", is_need_refresh)
if is_need_refresh:
if areas is None:
if debugMode:
print("use area keyword #4", area_keyword_4)
# only when keyword#4 filled to query.
if len(area_keyword_4) > 0 :
is_need_refresh, areas = get_tixcraft_target_area(el, area_keyword_4, area_auto_select_mode, pass_1_seat_remaining_enable)
if debugMode:
print("is_need_refresh for keyword4:", is_need_refresh)
area_target = None area_target = None
if areas is not None: if areas is not None:
#print("area_auto_select_mode", area_auto_select_mode) #print("area_auto_select_mode", area_auto_select_mode)
@ -2609,7 +2651,7 @@ def kktix_reg_new(driver, url, answer_index, kktix_register_status_last):
# PURPOSE: get target area list. # PURPOSE: get target area list.
# PS: this is main block, use keyword to get rows. # PS: this is main block, use keyword to get rows.
# PS: it seems use date_auto_select_mode instead of area_auto_select_mode # PS: it seems use date_auto_select_mode instead of area_auto_select_mode
def get_fami_target_area(date_keyword, area_keyword_1, area_keyword_2, area_auto_select_mode): def get_fami_target_area(date_keyword, area_keyword_1, area_keyword_2, area_keyword_3, area_keyword_4, area_auto_select_mode):
show_debug_message = True # debug. show_debug_message = True # debug.
#show_debug_message = False # online #show_debug_message = False # online
@ -2722,11 +2764,24 @@ def get_fami_target_area(date_keyword, area_keyword_1, area_keyword_2, area_auto
if area_keyword_1 in area_html_text: if area_keyword_1 in area_html_text:
#print("is_match_area area_keyword_1") #print("is_match_area area_keyword_1")
is_match_area = True is_match_area = True
# check keyword 2 # check keyword 2
if len(area_keyword_2) > 0: if len(area_keyword_2) > 0:
if area_keyword_2 in area_html_text: if area_keyword_2 in area_html_text:
#print("is_match_area area_keyword_2") #print("is_match_area area_keyword_2")
is_match_area = True is_match_area = True
# check keyword 3
if len(area_keyword_3) > 0:
if area_keyword_3 in area_html_text:
#print("is_match_area area_keyword_3")
is_match_area = True
# check keyword 4
if len(area_keyword_4) > 0:
if area_keyword_4 in area_html_text:
#print("is_match_area area_keyword_4")
is_match_area = True
else: else:
is_match_area = True is_match_area = True
@ -2786,6 +2841,8 @@ def fami_home(driver, url):
global date_keyword global date_keyword
global area_keyword_1 global area_keyword_1
global area_keyword_2 global area_keyword_2
global area_keyword_3
global area_keyword_4
global area_auto_select_mode global area_auto_select_mode
@ -2858,7 +2915,7 @@ def fami_home(driver, url):
#--------------------------- #---------------------------
# part 2: select keywords # part 2: select keywords
#--------------------------- #---------------------------
areas = get_fami_target_area(date_keyword, area_keyword_1, area_keyword_2, area_auto_select_mode) areas = get_fami_target_area(date_keyword, area_keyword_1, area_keyword_2, area_keyword_3, area_keyword_4, area_auto_select_mode)
area_target = None area_target = None
if areas is not None: if areas is not None:
@ -3529,6 +3586,7 @@ def main():
, u'failed to check if window was closed' , u'failed to check if window was closed'
, u'Failed to establish a new connection' , u'Failed to establish a new connection'
, u'Connection refused' , u'Connection refused'
, u'disconnected'
, u'without establishing a connection'] , u'without establishing a connection']
for each_error_string in exit_bot_error_strings: for each_error_string in exit_bot_error_strings:
# for python2 # for python2
@ -3622,9 +3680,11 @@ def main():
global area_keyword_1 global area_keyword_1
global area_keyword_2 global area_keyword_2
global area_keyword_3
global area_keyword_4
if area_auto_select_enable: if area_auto_select_enable:
area_auto_select(driver, url, area_keyword_1, area_keyword_2, area_auto_select_mode, pass_1_seat_remaining_enable) area_auto_select(driver, url, area_keyword_1, area_keyword_2, area_keyword_3, area_keyword_4, area_auto_select_mode, pass_1_seat_remaining_enable)
if '/ticket/verify/' in url: if '/ticket/verify/' in url:
tixcraft_verify(driver, url) tixcraft_verify(driver, url)

View File

@ -19,7 +19,7 @@ import sys
import platform import platform
import json import json
CONST_APP_VERSION = u"MaxBot (2022.11.08)" CONST_APP_VERSION = u"MaxBot (2022.11.09)"
CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom" CONST_FROM_TOP_TO_BOTTOM = u"from top to bottom"
CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top" CONST_FROM_BOTTOM_TO_TOP = u"from bottom to top"
@ -86,6 +86,8 @@ def btn_save_act(slience_mode=False):
global chk_state_area_auto_select global chk_state_area_auto_select
global txt_area_keyword_1 global txt_area_keyword_1
global txt_area_keyword_2 global txt_area_keyword_2
global txt_area_keyword_3
global txt_area_keyword_4
global combo_date_auto_select_mode global combo_date_auto_select_mode
global combo_area_auto_select_mode global combo_area_auto_select_mode
@ -137,6 +139,8 @@ def btn_save_act(slience_mode=False):
config_dict["tixcraft"]["area_auto_select"]["enable"] = bool(chk_state_area_auto_select.get()) config_dict["tixcraft"]["area_auto_select"]["enable"] = bool(chk_state_area_auto_select.get())
config_dict["tixcraft"]["area_auto_select"]["area_keyword_1"] = txt_area_keyword_1.get().strip() config_dict["tixcraft"]["area_auto_select"]["area_keyword_1"] = txt_area_keyword_1.get().strip()
config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"] = txt_area_keyword_2.get().strip() config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"] = txt_area_keyword_2.get().strip()
config_dict["tixcraft"]["area_auto_select"]["area_keyword_3"] = txt_area_keyword_3.get().strip()
config_dict["tixcraft"]["area_auto_select"]["area_keyword_4"] = txt_area_keyword_4.get().strip()
config_dict["tixcraft"]["date_auto_select"]["mode"] = combo_date_auto_select_mode.get().strip() config_dict["tixcraft"]["date_auto_select"]["mode"] = combo_date_auto_select_mode.get().strip()
config_dict["tixcraft"]["area_auto_select"]["mode"] = combo_area_auto_select_mode.get().strip() config_dict["tixcraft"]["area_auto_select"]["mode"] = combo_area_auto_select_mode.get().strip()
@ -316,10 +320,18 @@ def showHideTixcraftBlocks():
global area_keyword_1_index global area_keyword_1_index
global area_keyword_2_index global area_keyword_2_index
global area_keyword_3_index
global area_keyword_4_index
global lbl_area_keyword_1 global lbl_area_keyword_1
global lbl_area_keyword_2 global lbl_area_keyword_2
global lbl_area_keyword_3
global lbl_area_keyword_4
global txt_area_keyword_1 global txt_area_keyword_1
global txt_area_keyword_2 global txt_area_keyword_2
global txt_area_keyword_3
global txt_area_keyword_4
is_date_set_to_enable = bool(chk_state_date_auto_select.get()) is_date_set_to_enable = bool(chk_state_date_auto_select.get())
is_area_set_to_enable = bool(chk_state_area_auto_select.get()) is_area_set_to_enable = bool(chk_state_area_auto_select.get())
@ -351,6 +363,12 @@ def showHideTixcraftBlocks():
lbl_area_keyword_2.grid(column=0, row=area_keyword_2_index, sticky = E) lbl_area_keyword_2.grid(column=0, row=area_keyword_2_index, sticky = E)
txt_area_keyword_2.grid(column=1, row=area_keyword_2_index, sticky = W) txt_area_keyword_2.grid(column=1, row=area_keyword_2_index, sticky = W)
lbl_area_keyword_3.grid(column=0, row=area_keyword_3_index, sticky = E)
txt_area_keyword_3.grid(column=1, row=area_keyword_3_index, sticky = W)
lbl_area_keyword_4.grid(column=0, row=area_keyword_4_index, sticky = E)
txt_area_keyword_4.grid(column=1, row=area_keyword_4_index, sticky = W)
else: else:
# hide # hide
lbl_area_auto_select_mode.grid_forget() lbl_area_auto_select_mode.grid_forget()
@ -362,6 +380,12 @@ def showHideTixcraftBlocks():
lbl_area_keyword_2.grid_forget() lbl_area_keyword_2.grid_forget()
txt_area_keyword_2.grid_forget() txt_area_keyword_2.grid_forget()
lbl_area_keyword_3.grid_forget()
txt_area_keyword_3.grid_forget()
lbl_area_keyword_4.grid_forget()
txt_area_keyword_4.grid_forget()
def MainMenu(root): def MainMenu(root):
global UI_PADDING_X global UI_PADDING_X
@ -397,6 +421,8 @@ def MainMenu(root):
area_auto_select_mode = "" area_auto_select_mode = ""
area_keyword_1 = "" area_keyword_1 = ""
area_keyword_2 = "" area_keyword_2 = ""
area_keyword_3 = ""
area_keyword_4 = ""
pass_1_seat_remaining_enable = False # default not checked. pass_1_seat_remaining_enable = False # default not checked.
pass_date_is_sold_out_enable = False # default not checked. pass_date_is_sold_out_enable = False # default not checked.
@ -493,6 +519,15 @@ def MainMenu(root):
area_keyword_2 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"] area_keyword_2 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"]
area_keyword_2 = area_keyword_2.strip() area_keyword_2 = area_keyword_2.strip()
if 'area_keyword_3' in config_dict["tixcraft"]["area_auto_select"]:
area_keyword_3 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_3"]
area_keyword_3 = area_keyword_3.strip()
if 'area_keyword_4' in config_dict["tixcraft"]["area_auto_select"]:
area_keyword_4 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_4"]
area_keyword_4 = area_keyword_4.strip()
pass_1_seat_remaining_enable = False pass_1_seat_remaining_enable = False
if 'pass_1_seat_remaining' in config_dict["tixcraft"]: if 'pass_1_seat_remaining' in config_dict["tixcraft"]:
pass_1_seat_remaining_enable = config_dict["tixcraft"]["pass_1_seat_remaining"] pass_1_seat_remaining_enable = config_dict["tixcraft"]["pass_1_seat_remaining"]
@ -534,6 +569,8 @@ def MainMenu(root):
print("area_auto_select_mode", area_auto_select_mode) print("area_auto_select_mode", area_auto_select_mode)
print("area_keyword_1", area_keyword_1) print("area_keyword_1", area_keyword_1)
print("area_keyword_2", area_keyword_2) print("area_keyword_2", area_keyword_2)
print("area_keyword_3", area_keyword_3)
print("area_keyword_4", area_keyword_4)
print("pass_1_seat_remaining", pass_1_seat_remaining_enable) print("pass_1_seat_remaining", pass_1_seat_remaining_enable)
print("pass_date_is_sold_out", pass_date_is_sold_out_enable) print("pass_date_is_sold_out", pass_date_is_sold_out_enable)
@ -840,6 +877,36 @@ def MainMenu(root):
group_row_count+=1 group_row_count+=1
global area_keyword_3_index
area_keyword_3_index = group_row_count
global lbl_area_keyword_3
lbl_area_keyword_3 = Label(frame_group_tixcraft, text="Area Keyword #3")
lbl_area_keyword_3.grid(column=0, row=area_keyword_3_index, sticky = E)
global txt_area_keyword_3
global txt_area_keyword_3_value
txt_area_keyword_3_value = StringVar(frame_group_tixcraft, value=area_keyword_3)
txt_area_keyword_3 = Entry(frame_group_tixcraft, width=20, textvariable = txt_area_keyword_3_value)
txt_area_keyword_3.grid(column=1, row=area_keyword_3_index, sticky = W)
group_row_count+=1
global area_keyword_4_index
area_keyword_4_index = group_row_count
global lbl_area_keyword_4
lbl_area_keyword_4 = Label(frame_group_tixcraft, text="Area Keyword #4")
lbl_area_keyword_4.grid(column=0, row=area_keyword_4_index, sticky = E)
global txt_area_keyword_4
global txt_area_keyword_4_value
txt_area_keyword_4_value = StringVar(frame_group_tixcraft, value=area_keyword_4)
txt_area_keyword_4 = Entry(frame_group_tixcraft, width=20, textvariable = txt_area_keyword_4_value)
txt_area_keyword_4.grid(column=1, row=area_keyword_4_index, sticky = W)
group_row_count+=1
lbl_pass_1_seat_remaining = Label(frame_group_tixcraft, text="Pass 1 seat remaining") lbl_pass_1_seat_remaining = Label(frame_group_tixcraft, text="Pass 1 seat remaining")
lbl_pass_1_seat_remaining.grid(column=0, row=group_row_count, sticky = E) lbl_pass_1_seat_remaining.grid(column=0, row=group_row_count, sticky = E)
@ -927,7 +994,7 @@ def main():
GUI = MainMenu(root) GUI = MainMenu(root)
GUI_SIZE_WIDTH = 420 GUI_SIZE_WIDTH = 420
GUI_SIZE_HEIGHT = 455 GUI_SIZE_HEIGHT = 495
GUI_SIZE_MACOS = str(GUI_SIZE_WIDTH) + 'x' + str(GUI_SIZE_HEIGHT) GUI_SIZE_MACOS = str(GUI_SIZE_WIDTH) + 'x' + str(GUI_SIZE_HEIGHT)
GUI_SIZE_WINDOWS=str(GUI_SIZE_WIDTH-60) + 'x' + str(GUI_SIZE_HEIGHT-20) GUI_SIZE_WINDOWS=str(GUI_SIZE_WIDTH-60) + 'x' + str(GUI_SIZE_HEIGHT-20)