block/external: more sanity checks
This commit is contained in:
parent
f31cb768ea
commit
592aa16734
1 changed files with 21 additions and 7 deletions
|
@ -1,3 +1,4 @@
|
|||
import datetime
|
||||
from typing import Tuple
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
@ -36,8 +37,8 @@ class BlockExternalAutomation(BaseAutomation):
|
|||
else:
|
||||
results[h2[i].text] = []
|
||||
i += 1
|
||||
|
||||
activities = []
|
||||
blocked_proxies = []
|
||||
for vp in results:
|
||||
if vp not in app.config['EXTERNAL_VANTAGE_POINTS']:
|
||||
continue
|
||||
|
@ -56,16 +57,29 @@ class BlockExternalAutomation(BaseAutomation):
|
|||
if proxy.deprecated:
|
||||
print("Proxy already marked blocked")
|
||||
continue
|
||||
if proxy.added < datetime.datetime.utcnow() - datetime.timedelta(hours=3):
|
||||
activities.append(Activity(
|
||||
activity_type="block_warning",
|
||||
text=(
|
||||
f"Proxy {proxy.url} for {proxy.origin.domain_name} detected blocked according to "
|
||||
"external source. REFUSING to rotate because this proxy is less than 3 hours old.")))
|
||||
continue
|
||||
blocked_proxies.append(proxy)
|
||||
if len(blocked_proxies) <= 15:
|
||||
for proxy in blocked_proxies:
|
||||
activities.append(Activity(
|
||||
activity_type="block",
|
||||
text=(f"Proxy {proxy.url} for {proxy.origin.domain_name} detected blocked according to external source. "
|
||||
"Rotation scheduled.")
|
||||
text=(f"Proxy {proxy.url} for {proxy.origin.domain_name} detected blocked according to external "
|
||||
"source. Rotation scheduled.")
|
||||
))
|
||||
proxy.deprecate(reason="external")
|
||||
for a in activities:
|
||||
db.session.add(a)
|
||||
db.session.commit()
|
||||
else:
|
||||
activities.append(Activity(
|
||||
activity_type="block_warning",
|
||||
text=(
|
||||
"More than 15 proxies were marked blocked according to external source. REFUSING to rotate.")))
|
||||
for a in activities:
|
||||
a.notify()
|
||||
|
||||
db.session.add(a)
|
||||
db.session.commit()
|
||||
return True, ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue