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 typing import Tuple
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
@ -36,8 +37,8 @@ class BlockExternalAutomation(BaseAutomation):
|
||||||
else:
|
else:
|
||||||
results[h2[i].text] = []
|
results[h2[i].text] = []
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
activities = []
|
activities = []
|
||||||
|
blocked_proxies = []
|
||||||
for vp in results:
|
for vp in results:
|
||||||
if vp not in app.config['EXTERNAL_VANTAGE_POINTS']:
|
if vp not in app.config['EXTERNAL_VANTAGE_POINTS']:
|
||||||
continue
|
continue
|
||||||
|
@ -56,16 +57,29 @@ class BlockExternalAutomation(BaseAutomation):
|
||||||
if proxy.deprecated:
|
if proxy.deprecated:
|
||||||
print("Proxy already marked blocked")
|
print("Proxy already marked blocked")
|
||||||
continue
|
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(
|
activities.append(Activity(
|
||||||
activity_type="block",
|
activity_type="block",
|
||||||
text=(f"Proxy {proxy.url} for {proxy.origin.domain_name} detected blocked according to external source. "
|
text=(f"Proxy {proxy.url} for {proxy.origin.domain_name} detected blocked according to external "
|
||||||
"Rotation scheduled.")
|
"source. Rotation scheduled.")
|
||||||
))
|
))
|
||||||
proxy.deprecate(reason="external")
|
proxy.deprecate(reason="external")
|
||||||
for a in activities:
|
else:
|
||||||
db.session.add(a)
|
activities.append(Activity(
|
||||||
db.session.commit()
|
activity_type="block_warning",
|
||||||
|
text=(
|
||||||
|
"More than 15 proxies were marked blocked according to external source. REFUSING to rotate.")))
|
||||||
for a in activities:
|
for a in activities:
|
||||||
a.notify()
|
a.notify()
|
||||||
|
db.session.add(a)
|
||||||
|
db.session.commit()
|
||||||
return True, ""
|
return True, ""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue