add area keyword #2

master
Max Yao 2019-10-27 09:31:22 +08:00
parent 4898a52aa1
commit 4423b28139
3 changed files with 204 additions and 117 deletions

View File

@ -39,7 +39,7 @@ logger = logging.getLogger('logger')
#附註1沒有寫的很好很多地方應該可以模組化。 #附註1沒有寫的很好很多地方應該可以模組化。
#附註2 #附註2
CONST_APP_VERSION = u"MaxBot (2019.10.23)" CONST_APP_VERSION = u"MaxBot (2019.10.26)"
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"
@ -83,6 +83,9 @@ area_auto_select_enable = None
area_auto_select_mode = None area_auto_select_mode = None
area_keyword = None area_keyword = None
area_keyword_1 = None
area_keyword_2 = None
kktix_area_auto_select_mode = None kktix_area_auto_select_mode = None
kktix_area_keyword = None kktix_area_keyword = None
@ -153,9 +156,13 @@ if not config_dict is None:
if not area_auto_select_mode in CONST_SELECT_OPTIONS_ARRAY: if not area_auto_select_mode in CONST_SELECT_OPTIONS_ARRAY:
area_auto_select_mode = CONST_SELECT_ORDER_DEFAULT area_auto_select_mode = CONST_SELECT_ORDER_DEFAULT
if 'area_keyword' in config_dict["tixcraft"]["area_auto_select"]: if 'area_keyword_1' in config_dict["tixcraft"]["area_auto_select"]:
area_keyword = config_dict["tixcraft"]["area_auto_select"]["area_keyword"] area_keyword_1 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_1"]
area_keyword = area_keyword.strip() area_keyword_1 = area_keyword_1.strip()
if 'area_keyword_2' in config_dict["tixcraft"]["area_auto_select"]:
area_keyword_2 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"]
area_keyword_2 = area_keyword_2.strip()
# output config: # output config:
print("version", CONST_APP_VERSION) print("version", CONST_APP_VERSION)
@ -179,7 +186,8 @@ if not config_dict is None:
print("area_auto_select_enable", area_auto_select_enable) print("area_auto_select_enable", area_auto_select_enable)
print("area_auto_select_mode", area_auto_select_mode) print("area_auto_select_mode", area_auto_select_mode)
print("area_keyword", area_keyword) print("area_keyword_1", area_keyword_1)
print("area_keyword_2", area_keyword_2)
# entry point # entry point
# 說明:自動開啟第一個的網頁 # 說明:自動開啟第一個的網頁
@ -691,24 +699,12 @@ def date_auto_select(url):
pass pass
#print("find .btn-next fail:", exc) #print("find .btn-next fail:", exc)
# PURPOSE: get target area list.
# PS: auto refresh condition 1: no keyword + no hyperlink. def get_tixcraft_target_area(el, area_keyword):
# PS: auto refresh condition 2: with keyword + no hyperlink.
def area_auto_select(url):
if 'tixcraft.com/ticket/area/' in url:
#driver.switch_to.default_content()
el = None
try:
el = driver.find_element(By.CSS_SELECTOR, '.zone')
except Exception as exc:
print("find .zone fail, do nothing.")
if el is not None:
areas = None areas = None
is_need_refresh = False is_need_refresh = False
if el is not None:
if len(area_keyword) == 0: if len(area_keyword) == 0:
try: try:
areas = el.find_elements(By.TAG_NAME, "a") areas = el.find_elements(By.TAG_NAME, "a")
@ -765,6 +761,29 @@ def area_auto_select(url):
break break
#print("row_text:" + row_text) #print("row_text:" + row_text)
#print("match:" + area_keyword) #print("match:" + area_keyword)
if len(areas) == 0:
areas = None
return is_need_refresh, areas
# PS: auto refresh condition 1: no keyword + no hyperlink.
# PS: auto refresh condition 2: with keyword + no hyperlink.
def area_auto_select(url):
if 'tixcraft.com/ticket/area/' in url:
#driver.switch_to.default_content()
el = None
try:
el = driver.find_element(By.CSS_SELECTOR, '.zone')
except Exception as exc:
print("find .zone fail, do nothing.")
if el is not None:
is_need_refresh, areas = get_tixcraft_target_area(el, area_keyword_1)
if not is_need_refresh:
if areas is None:
print("use area keyword #2", area_keyword_2)
is_need_refresh, areas = get_tixcraft_target_area(el, area_keyword_2)
area_target = None area_target = None
if areas is not None: if areas is not None:
@ -799,7 +818,6 @@ def area_auto_select(url):
print(exc) print(exc)
pass pass
# auto refresh for area list page. # auto refresh for area list page.
if is_need_refresh: if is_need_refresh:
try: try:
@ -998,7 +1016,7 @@ def tixcraft_verify(url):
if ret: if ret:
# retry # retry
for i in range(5): for i in range(3):
form_input = None form_input = None
try: try:
form_input = driver.find_element(By.CSS_SELECTOR, '#submitButton') form_input = driver.find_element(By.CSS_SELECTOR, '#submitButton')
@ -1013,6 +1031,29 @@ def tixcraft_verify(url):
print("find submit button fail") print("find submit button fail")
print(exc) print(exc)
pass pass
else:
is_auto_focus_enable = False
if is_auto_focus_enable:
form_input = None
try:
form_input = driver.find_element(By.CSS_SELECTOR, '#checkCode')
if form_input is not None:
default_value = form_input.get_attribute('value')
is_need_focus = False
if default_value is None:
is_need_focus = True
else:
if len(default_value) == 0:
is_need_focus = True
if is_need_focus:
if form_input.is_enabled():
form_input.click()
time.sleep(0.2)
else:
print("find captcha input field fail")
except Exception as exc:
print("find verify fail")
pass
return ret return ret
@ -1810,13 +1851,9 @@ def fami_date_auto_select(url):
if match_keyword_row: if match_keyword_row:
break break
# purpose: area auto select
# return: # PURPOSE: get target area list.
# True: area block appear. def get_fami_target_area(area_keyword):
# False: area block not appear.
# ps: return value for date auto select.
def fami_area_auto_select(url):
ret = False
areas = None areas = None
area_list = None area_list = None
@ -1856,11 +1893,29 @@ def fami_area_auto_select(url):
#print("area row_text:", row_index, row_text) #print("area row_text:", row_index, row_text)
if area_keyword in row_text: if area_keyword in row_text:
areas.append(row) areas.append(row)
if len(areas)==0:
areas = None
except Exception as exc: except Exception as exc:
print("find #game_page date list fail") print("find #game_page date list fail")
#print(exc) #print(exc)
return areas
# purpose: area auto select
# return:
# True: area block appear.
# False: area block not appear.
# ps: return value for date auto select.
def fami_area_auto_select(url):
ret = False
areas = get_fami_target_area(area_keyword_1)
if areas is None:
print("use area keyword #2", area_keyword_2)
areas = get_fami_target_area(area_keyword_2)
area = None area = 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)

View File

@ -1 +1 @@
{"tixcraft": {"area_auto_select": {"enable": true, "mode": "random", "area_keyword": ""}, "date_auto_select": {"enable": true, "date_keyword": "", "mode": "from top to bottom"}}, "homepage1": "https://kktix.com", "homepage2": "https://tixcraft.com", "facebook_account": "", "browser1": "chrome", "browser2": "firefox", "kktix": {"auto_fill_ticket_price": "$1,500", "answer_dictionary": "", "area_keyword": "", "auto_press_next_step_button": true, "auto_fill_ticket_number": true, "area_mode": "random"}, "ticket_number": 2, "homepage": "https://tixcraft.com", "browser": "chrome"} {"tixcraft": {"area_auto_select": {"enable": true, "area_keyword": "", "mode": "from top to bottom", "area_keyword_2": "", "area_keyword_1": ""}, "date_auto_select": {"enable": true, "date_keyword": "", "mode": "from top to bottom"}}, "homepage1": "https://kktix.com", "homepage2": "https://tixcraft.com", "facebook_account": "", "browser1": "chrome", "browser2": "firefox", "kktix": {"auto_fill_ticket_price": "$1,500", "answer_dictionary": "", "area_keyword": "", "auto_press_next_step_button": true, "auto_fill_ticket_number": true, "area_mode": "random"}, "ticket_number": 2, "homepage": "https://tixcraft.com", "browser": "chrome"}

View File

@ -16,7 +16,7 @@ import os
import sys import sys
import json import json
CONST_APP_VERSION = u"MaxBot (2019.10.23)" CONST_APP_VERSION = u"MaxBot (2019.10.26)"
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"
@ -77,7 +77,8 @@ def btn_save_act(slience_mode=False):
global chk_state_date_auto_select global chk_state_date_auto_select
global txt_date_keyword global txt_date_keyword
global chk_state_area_auto_select global chk_state_area_auto_select
global txt_area_keyword global txt_area_keyword_1
global txt_area_keyword_2
global combo_date_auto_select_mode global combo_date_auto_select_mode
global combo_area_auto_select_mode global combo_area_auto_select_mode
@ -118,7 +119,8 @@ def btn_save_act(slience_mode=False):
config_dict["tixcraft"]["date_auto_select"]["date_keyword"] = txt_date_keyword.get().strip() config_dict["tixcraft"]["date_auto_select"]["date_keyword"] = txt_date_keyword.get().strip()
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"] = txt_area_keyword.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"]["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()
@ -250,16 +252,19 @@ def showHideTixcraftBlocks():
global lbl_area_auto_select_mode global lbl_area_auto_select_mode
global combo_area_auto_select_mode global combo_area_auto_select_mode
global area_keyword_index global area_keyword_1_index
global lbl_area_keyword global area_keyword_2_index
global txt_area_keyword global lbl_area_keyword_1
global lbl_area_keyword_2
global txt_area_keyword_1
global txt_area_keyword_2
new_date_enable = bool(chk_state_date_auto_select.get()) is_date_set_to_enable = bool(chk_state_date_auto_select.get())
new_area_enable = bool(chk_state_area_auto_select.get()) is_area_set_to_enable = bool(chk_state_area_auto_select.get())
#print("new new_date_enable value:", new_date_enable) #print("now is_date_set_to_enable value:", is_date_set_to_enable)
#print("new new_area_enable value:", new_area_enable) #print("now is_area_set_to_enable value:", is_area_set_to_enable)
if new_date_enable: if is_date_set_to_enable:
# show # show
lbl_date_auto_select_mode.grid(column=0, row=date_auto_select_mode_index, sticky = E) lbl_date_auto_select_mode.grid(column=0, row=date_auto_select_mode_index, sticky = E)
combo_date_auto_select_mode.grid(column=1, row=date_auto_select_mode_index, sticky = W) combo_date_auto_select_mode.grid(column=1, row=date_auto_select_mode_index, sticky = W)
@ -274,20 +279,26 @@ def showHideTixcraftBlocks():
lbl_date_keyword.grid_forget() lbl_date_keyword.grid_forget()
txt_date_keyword.grid_forget() txt_date_keyword.grid_forget()
if new_area_enable: if is_area_set_to_enable:
# show # show
lbl_area_auto_select_mode.grid(column=0, row=area_auto_select_index, sticky = E) lbl_area_auto_select_mode.grid(column=0, row=area_auto_select_index, sticky = E)
combo_area_auto_select_mode.grid(column=1, row=area_auto_select_index, sticky = W) combo_area_auto_select_mode.grid(column=1, row=area_auto_select_index, sticky = W)
lbl_area_keyword.grid(column=0, row=area_keyword_index, sticky = E) lbl_area_keyword_1.grid(column=0, row=area_keyword_1_index, sticky = E)
txt_area_keyword.grid(column=1, row=area_keyword_index, sticky = W) txt_area_keyword_1.grid(column=1, row=area_keyword_1_index, sticky = W)
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)
else: else:
# hide # hide
lbl_area_auto_select_mode.grid_forget() lbl_area_auto_select_mode.grid_forget()
combo_area_auto_select_mode.grid_forget() combo_area_auto_select_mode.grid_forget()
lbl_area_keyword.grid_forget() lbl_area_keyword_1.grid_forget()
txt_area_keyword.grid_forget() txt_area_keyword_1.grid_forget()
lbl_area_keyword_2.grid_forget()
txt_area_keyword_2.grid_forget()
def MainMenu(root): def MainMenu(root):
@ -319,7 +330,8 @@ def MainMenu(root):
area_auto_select_enable = None area_auto_select_enable = None
area_auto_select_mode = "" area_auto_select_mode = ""
area_keyword = "" area_keyword_1 = ""
area_keyword_2 = ""
global config_dict global config_dict
if not config_dict is None: if not config_dict is None:
@ -381,9 +393,13 @@ def MainMenu(root):
if not area_auto_select_mode in CONST_SELECT_OPTIONS_ARRAY: if not area_auto_select_mode in CONST_SELECT_OPTIONS_ARRAY:
area_auto_select_mode = CONST_SELECT_ORDER_DEFAULT area_auto_select_mode = CONST_SELECT_ORDER_DEFAULT
if 'area_keyword' in config_dict["tixcraft"]["area_auto_select"]: if 'area_keyword_1' in config_dict["tixcraft"]["area_auto_select"]:
area_keyword = config_dict["tixcraft"]["area_auto_select"]["area_keyword"] area_keyword_1 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_1"]
area_keyword = area_keyword.strip() area_keyword_1 = area_keyword_1.strip()
if 'area_keyword_2' in config_dict["tixcraft"]["area_auto_select"]:
area_keyword_2 = config_dict["tixcraft"]["area_auto_select"]["area_keyword_2"]
area_keyword_2 = area_keyword_2.strip()
# output config: # output config:
print("homepage", homepage) print("homepage", homepage)
@ -407,7 +423,8 @@ def MainMenu(root):
print("area_auto_select_enable", area_auto_select_enable) print("area_auto_select_enable", area_auto_select_enable)
print("area_auto_select_mode", area_auto_select_mode) print("area_auto_select_mode", area_auto_select_mode)
print("area_keyword", area_keyword) print("area_keyword_1", area_keyword_1)
print("area_keyword_2", area_keyword_2)
else: else:
print('config is none') print('config is none')
@ -638,18 +655,33 @@ def MainMenu(root):
group_row_count+=1 group_row_count+=1
global area_keyword_index global area_keyword_1_index
area_keyword_index = group_row_count area_keyword_1_index = group_row_count
global lbl_area_keyword global lbl_area_keyword_1
lbl_area_keyword = Label(frame_group_tixcraft, text="Area Keyword") lbl_area_keyword_1 = Label(frame_group_tixcraft, text="Area Keyword #1")
lbl_area_keyword.grid(column=0, row=area_keyword_index, sticky = E) lbl_area_keyword_1.grid(column=0, row=area_keyword_1_index, sticky = E)
global txt_area_keyword global txt_area_keyword_1
global txt_ares_keyword_value global txt_area_keyword_1_value
txt_ares_keyword_value = StringVar(frame_group_tixcraft, value=area_keyword) txt_area_keyword_1_value = StringVar(frame_group_tixcraft, value=area_keyword_1)
txt_area_keyword = Entry(frame_group_tixcraft, width=20, textvariable = txt_ares_keyword_value) txt_area_keyword_1 = Entry(frame_group_tixcraft, width=20, textvariable = txt_area_keyword_1_value)
txt_area_keyword.grid(column=1, row=area_keyword_index, sticky = W) txt_area_keyword_1.grid(column=1, row=area_keyword_1_index, sticky = W)
group_row_count+=1
global area_keyword_2_index
area_keyword_2_index = group_row_count
global lbl_area_keyword_2
lbl_area_keyword_2 = Label(frame_group_tixcraft, text="Area Keyword #2")
lbl_area_keyword_2.grid(column=0, row=area_keyword_2_index, sticky = E)
global txt_area_keyword_2
global txt_area_keyword_2_value
txt_area_keyword_2_value = StringVar(frame_group_tixcraft, value=area_keyword_2)
txt_area_keyword_2 = Entry(frame_group_tixcraft, width=20, textvariable = txt_area_keyword_2_value)
txt_area_keyword_2.grid(column=1, row=area_keyword_2_index, sticky = W)
global frame_group_tixcraft_index global frame_group_tixcraft_index
frame_group_tixcraft_index = row_count frame_group_tixcraft_index = row_count
@ -697,7 +729,7 @@ def main():
GUI = MainMenu(root) GUI = MainMenu(root)
GUI_SIZE_WIDTH = 420 GUI_SIZE_WIDTH = 420
GUI_SIZE_HEIGHT = 340 GUI_SIZE_HEIGHT = 370
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)