0.2.2
This commit is contained in:
@@ -675,6 +675,19 @@ def is_forbidden_time() -> bool:
|
|||||||
end = now.replace(hour=20, minute=0, second=0, microsecond=0)
|
end = now.replace(hour=20, minute=0, second=0, microsecond=0)
|
||||||
return start <= now < end
|
return start <= now < end
|
||||||
|
|
||||||
|
def wait_until_out_of_forbidden(interval_sec: float = 5.0, stop_event: threading.Event | None = None) -> None:
|
||||||
|
"""
|
||||||
|
在禁跑时段内循环等待,直到禁跑时段结束
|
||||||
|
|
||||||
|
参数:
|
||||||
|
interval_sec: 轮询间隔秒数
|
||||||
|
stop_event: 可选停止事件,若设置则在等待期间可提前结束
|
||||||
|
"""
|
||||||
|
while is_forbidden_time():
|
||||||
|
if stop_event is not None and stop_event.wait(timeout=interval_sec):
|
||||||
|
break
|
||||||
|
time.sleep(interval_sec)
|
||||||
|
|
||||||
|
|
||||||
def seconds_until(hour: int, minute: int) -> float:
|
def seconds_until(hour: int, minute: int) -> float:
|
||||||
"""
|
"""
|
||||||
@@ -782,9 +795,8 @@ def main():
|
|||||||
if stop_event.wait(timeout=300):
|
if stop_event.wait(timeout=300):
|
||||||
continue
|
continue
|
||||||
cleanup_all_browsers()
|
cleanup_all_browsers()
|
||||||
secs = seconds_until(20, 0)
|
logger.info("处于禁跑时段,等待至禁跑结束")
|
||||||
logger.info(f"处于禁跑时段,休眠至20:00,剩余 {int(secs)} 秒")
|
wait_until_out_of_forbidden()
|
||||||
time.sleep(secs)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
executor = ThreadPoolExecutor(max_workers=len(proxies))
|
executor = ThreadPoolExecutor(max_workers=len(proxies))
|
||||||
@@ -815,6 +827,7 @@ def main():
|
|||||||
pass
|
pass
|
||||||
time.sleep(300)
|
time.sleep(300)
|
||||||
cleanup_all_browsers()
|
cleanup_all_browsers()
|
||||||
|
wait_until_out_of_forbidden()
|
||||||
break
|
break
|
||||||
for f, proxy in list(futures_map.items()):
|
for f, proxy in list(futures_map.items()):
|
||||||
if f.done() and not stop_event.is_set() and not restart_event.is_set():
|
if f.done() and not stop_event.is_set() and not restart_event.is_set():
|
||||||
|
|||||||
@@ -93,4 +93,4 @@ hz = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
proxy_list = xy
|
proxy_list = work
|
||||||
Reference in New Issue
Block a user