lint(proxy): lint

This commit is contained in:
Iain Learmonth 2023-05-03 14:48:40 +01:00
parent 08205647a5
commit 8689f1331d

View file

@ -70,7 +70,7 @@ class ProxyMetaAutomation(BaseAutomation):
def automate(self, full: bool = False) -> Tuple[bool, str]: def automate(self, full: bool = False) -> Tuple[bool, str]:
# Deprecate orphaned proxies, old proxies and mismatched proxies # Deprecate orphaned proxies, old proxies and mismatched proxies
proxies = Proxy.query.filter( proxies: List[Proxy] = Proxy.query.filter(
Proxy.deprecated.is_(None), Proxy.deprecated.is_(None),
Proxy.destroyed.is_(None), Proxy.destroyed.is_(None),
).all() ).all()
@ -78,9 +78,9 @@ class ProxyMetaAutomation(BaseAutomation):
if proxy.origin.destroyed is not None: if proxy.origin.destroyed is not None:
proxy.deprecate(reason="origin_destroyed") proxy.deprecate(reason="origin_destroyed")
if proxy.origin_id in current_app.config.get("DAILY_REPLACEMENT_ORIGINS", []): if proxy.origin_id in current_app.config.get("DAILY_REPLACEMENT_ORIGINS", []):
max_age_cutoff = datetime.datetime.utcnow() - datetime.timedelta(days=1, seconds=86400 * random.random()) max_age_cutoff = datetime.datetime.utcnow() - datetime.timedelta(days=1, seconds=86400 * random.random()) # nosec: B311
else: else:
max_age_cutoff = datetime.datetime.utcnow() - datetime.timedelta(days=5, seconds=86400 * random.random()) max_age_cutoff = datetime.datetime.utcnow() - datetime.timedelta(days=5, seconds=86400 * random.random()) # nosec: B311
if proxy.added < max_age_cutoff: if proxy.added < max_age_cutoff:
proxy.deprecate(reason="max_age_reached") proxy.deprecate(reason="max_age_reached")
if proxy.origin.smart and not PROXY_PROVIDERS[proxy.provider].smart_proxies: # type: ignore[attr-defined] if proxy.origin.smart and not PROXY_PROVIDERS[proxy.provider].smart_proxies: # type: ignore[attr-defined]
@ -101,7 +101,7 @@ class ProxyMetaAutomation(BaseAutomation):
create_proxy(pool, origin) create_proxy(pool, origin)
# Destroy expired proxies # Destroy expired proxies
expiry_cutoff = datetime.datetime.utcnow() - datetime.timedelta(days=4) expiry_cutoff = datetime.datetime.utcnow() - datetime.timedelta(days=4)
proxies: List[Proxy] = Proxy.query.filter( proxies = Proxy.query.filter(
Proxy.destroyed.is_(None), Proxy.destroyed.is_(None),
Proxy.deprecated < expiry_cutoff Proxy.deprecated < expiry_cutoff
).all() ).all()