0.1.9
This commit is contained in:
@@ -2,6 +2,7 @@ from math import log
|
||||
import random
|
||||
from re import S
|
||||
import time
|
||||
from datetime import datetime
|
||||
from tkinter import N
|
||||
from DrissionPage import Chromium
|
||||
from loguru import logger
|
||||
@@ -573,6 +574,28 @@ def get_all_proxies() -> list[list[str]]:
|
||||
return [p.split(":") for p in proxy_list]
|
||||
|
||||
|
||||
def is_quiet_time() -> bool:
|
||||
"""
|
||||
判断当前是否处于禁跑时段(18:30~20:00)
|
||||
"""
|
||||
now = datetime.now()
|
||||
start = now.replace(hour=18, minute=30, second=0, microsecond=0)
|
||||
end = now.replace(hour=20, minute=0, second=0, microsecond=0)
|
||||
return start <= now < end
|
||||
|
||||
|
||||
def sleep_until_quiet_end():
|
||||
"""
|
||||
在禁跑时段内休眠至 20:00
|
||||
"""
|
||||
now = datetime.now()
|
||||
end = now.replace(hour=20, minute=0, second=0, microsecond=0)
|
||||
if now < end:
|
||||
seconds = (end - now).total_seconds()
|
||||
logger.info(f"当前处于禁跑时段,休眠至 20:00({int(seconds)} 秒)")
|
||||
time.sleep(seconds)
|
||||
|
||||
|
||||
"""指纹浏览器操作"""
|
||||
# 创建指纹浏览器
|
||||
|
||||
@@ -586,6 +609,9 @@ def create_fingerprint_browser(city: str | None = None):
|
||||
"""
|
||||
browser_id = None
|
||||
try:
|
||||
if is_quiet_time():
|
||||
logger.info("处于禁跑时段(18:30~20:00),跳过本次运行")
|
||||
return
|
||||
if city is not None:
|
||||
proxy = get_proxy(city)
|
||||
if proxy is None:
|
||||
@@ -649,6 +675,9 @@ def run_city_forever(city: str):
|
||||
city (str): 城市名称
|
||||
"""
|
||||
while True:
|
||||
if is_quiet_time():
|
||||
sleep_until_quiet_end()
|
||||
continue
|
||||
try:
|
||||
create_fingerprint_browser(city)
|
||||
except Exception as e:
|
||||
@@ -681,6 +710,9 @@ def run_random_ips_forever():
|
||||
持续使用随机 IP 执行流程:每次完成后关闭并删除浏览器再重建
|
||||
"""
|
||||
while True:
|
||||
if is_quiet_time():
|
||||
sleep_until_quiet_end()
|
||||
continue
|
||||
try:
|
||||
create_fingerprint_browser(None)
|
||||
except Exception as e:
|
||||
@@ -720,6 +752,9 @@ def create_fingerprint_browser_with_proxy(proxy: list[str]):
|
||||
"""
|
||||
browser_id = None
|
||||
try:
|
||||
if is_quiet_time():
|
||||
logger.info("处于禁跑时段(18:30~20:00),跳过本次运行")
|
||||
return
|
||||
if not proxy or len(proxy) < 4:
|
||||
logger.error("代理参数不完整,结束该线程")
|
||||
return
|
||||
@@ -770,6 +805,9 @@ def run_proxies_forever(proxy: list[str]):
|
||||
proxy (list[str]): `[host, port, user, pwd]`
|
||||
"""
|
||||
while True:
|
||||
if is_quiet_time():
|
||||
sleep_until_quiet_end()
|
||||
continue
|
||||
try:
|
||||
create_fingerprint_browser_with_proxy(proxy)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user