add new condifition to refresh page.

master
CHUN YU YAO 2021-03-22 17:07:28 +08:00
parent 28c00c4ca3
commit cbc80965b6
2 changed files with 61 additions and 54 deletions

View File

@ -44,7 +44,7 @@ warnings.simplefilter('ignore',InsecureRequestWarning)
#附註1沒有寫的很好很多地方應該可以模組化。 #附註1沒有寫的很好很多地方應該可以模組化。
#附註2 #附註2
CONST_APP_VERSION = u"MaxBot (2021.03.21)" CONST_APP_VERSION = u"MaxBot (2021.03.22)"
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"
@ -805,12 +805,16 @@ def date_auto_select(url):
#print("find .btn-next fail:", exc) #print("find .btn-next fail:", exc)
# PURPOSE: get target area list. # PURPOSE: get target area list.
# RETURN:
# is_need_refresh
# areas
def get_tixcraft_target_area(el, area_keyword): def get_tixcraft_target_area(el, area_keyword):
areas = None
is_need_refresh = False is_need_refresh = False
areas = None
area_list = None
area_list_count = 0
if el is not None: if el is not None:
area_list = None
try: try:
area_list = el.find_elements(By.TAG_NAME, 'a') area_list = el.find_elements(By.TAG_NAME, 'a')
except Exception as exc: except Exception as exc:
@ -818,71 +822,74 @@ def get_tixcraft_target_area(el, area_keyword):
pass pass
if area_list is not None: if area_list is not None:
if len(area_list) == 0: area_list_count = len(area_list)
if area_list_count == 0:
print("(with keyword) list is empty, do refresh!") print("(with keyword) list is empty, do refresh!")
is_need_refresh = True is_need_refresh = True
else: else:
print("(with keyword) list is None, do refresh!") print("(with keyword) list is None, do refresh!")
is_need_refresh = True is_need_refresh = True
if area_list is not None: if area_list_count > 0:
areas = [] areas = []
for row in area_list: for row in area_list:
row_is_enabled=False row_is_enabled=False
try:
row_is_enabled = row.is_enabled()
except Exception as exc:
pass
row_text = ""
if row_is_enabled:
try: try:
row_is_enabled = row.is_enabled() row_text = row.text
except Exception as exc: except Exception as exc:
pass print("get text fail")
break
row_text = "" if len(row_text) > 0:
if row_is_enabled: is_append_this_row = False
try:
row_text = row.text
except Exception as exc:
print("get text fail")
break
if len(row_text) > 0: if len(area_keyword) > 0:
is_append_this_row = False # must match keyword.
if area_keyword in row_text:
if len(area_keyword) > 0:
# must match keyword.
if area_keyword in row_text:
is_append_this_row = True
else:
# without keyword.
is_append_this_row = True is_append_this_row = True
else:
# without keyword.
is_append_this_row = True
if is_append_this_row: if is_append_this_row:
if pass_1_seat_remaining_enable: if pass_1_seat_remaining_enable:
area_item_font_el = None area_item_font_el = None
try: try:
#print('try to find font tag at row:', row_text) #print('try to find font tag at row:', row_text)
area_item_font_el = row.find_element(By.TAG_NAME, 'font') area_item_font_el = row.find_element(By.TAG_NAME, 'font')
if not area_item_font_el is None: if not area_item_font_el is None:
font_el_text = area_item_font_el.text font_el_text = area_item_font_el.text
#print('font tag text:', font_el_text) #print('font tag text:', font_el_text)
if font_el_text in CONT_STRING_1_SEATS_REMAINING: if font_el_text in CONT_STRING_1_SEATS_REMAINING:
#print("match pass 1 seats remaining 1 full text:", row_text) #print("match pass 1 seats remaining 1 full text:", row_text)
#print("match pass 1 seats remaining 2 font text:", font_el_text) #print("match pass 1 seats remaining 2 font text:", font_el_text)
is_append_this_row = False is_append_this_row = False
else: else:
#print("row withou font tag.") #print("row withou font tag.")
pass
except Exception as exc:
#print("find font text in a tag fail:", exc)
pass pass
except Exception as exc:
#print("find font text in a tag fail:", exc)
pass
if is_append_this_row: if is_append_this_row:
areas.append(row) areas.append(row)
if area_auto_select_mode == CONST_FROM_TOP_TO_BOTTOM: if area_auto_select_mode == CONST_FROM_TOP_TO_BOTTOM:
print("only need first item, break area list loop.") print("only need first item, break area list loop.")
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 if len(areas) == 0:
areas = None
is_need_refresh = True
return is_need_refresh, areas return is_need_refresh, areas

View File

@ -16,7 +16,7 @@ import os
import sys import sys
import json import json
CONST_APP_VERSION = u"MaxBot (2021.03.21)" CONST_APP_VERSION = u"MaxBot (2021.03.22)"
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"