chore:retry sleep
This commit is contained in:
parent
2f7fb3684e
commit
f0d76856cd
21
utils.py
21
utils.py
@ -22,6 +22,7 @@ from selenium_stealth import stealth
|
||||
import concurrent.futures
|
||||
import sys
|
||||
import importlib.util
|
||||
from time import sleep
|
||||
|
||||
timeout = 10
|
||||
max_retries = 3
|
||||
@ -33,6 +34,7 @@ def retry_func(func, retries=max_retries + 1, name=""):
|
||||
"""
|
||||
for i in range(retries):
|
||||
try:
|
||||
sleep(3)
|
||||
return func()
|
||||
except Exception as e:
|
||||
count = retries - 1
|
||||
@ -320,7 +322,7 @@ async def get_channels_by_online_search(names, callback):
|
||||
if not pageUrl:
|
||||
return channels
|
||||
github_actions = os.environ.get("GITHUB_ACTIONS")
|
||||
if github_actions:
|
||||
# if github_actions:
|
||||
proxy_list = get_proxy_list()
|
||||
response_times = await asyncio.gather(*(get_speed(url) for url in proxy_list))
|
||||
proxy_list_with_speed = [
|
||||
@ -329,8 +331,9 @@ async def get_channels_by_online_search(names, callback):
|
||||
if response_time is not None
|
||||
]
|
||||
proxy_list_with_speed.sort(key=lambda x: x[1])
|
||||
print(f"Proxy list with speed: {proxy_list_with_speed}")
|
||||
best_proxy = proxy_list_with_speed[0][0] if proxy_list_with_speed else None
|
||||
print(f"Using proxy: {best_proxy}")
|
||||
print(f"Using proxy: {best_proxy}, response time: {proxy_list_with_speed[0][1]}ms")
|
||||
start_time = time()
|
||||
|
||||
def process_channel_by_online_search(name):
|
||||
@ -344,17 +347,23 @@ async def get_channels_by_online_search(names, callback):
|
||||
EC.presence_of_element_located((By.XPATH, '//input[@type="text"]'))
|
||||
)
|
||||
)
|
||||
if search_box:
|
||||
search_box.clear()
|
||||
search_box.send_keys(name)
|
||||
submit_button = retry_func(
|
||||
lambda: wait.until(
|
||||
EC.element_to_be_clickable((By.XPATH, '//input[@type="submit"]'))
|
||||
EC.element_to_be_clickable(
|
||||
(By.XPATH, '//input[@type="submit"]')
|
||||
)
|
||||
)
|
||||
)
|
||||
if submit_button:
|
||||
driver.execute_script("arguments[0].click();", submit_button)
|
||||
isFavorite = name in config.favorite_list
|
||||
pageNum = (
|
||||
config.favorite_page_num if isFavorite else config.default_page_num
|
||||
config.favorite_page_num
|
||||
if isFavorite
|
||||
else config.default_page_num
|
||||
)
|
||||
for page in range(1, pageNum + 1):
|
||||
try:
|
||||
@ -369,7 +378,9 @@ async def get_channels_by_online_search(names, callback):
|
||||
)
|
||||
)
|
||||
)
|
||||
driver.execute_script("arguments[0].click();", page_link)
|
||||
driver.execute_script(
|
||||
"arguments[0].click();", page_link
|
||||
)
|
||||
source = re.sub(
|
||||
r"<!--.*?-->",
|
||||
"",
|
||||
|
Loading…
x
Reference in New Issue
Block a user