forked from AlexTrushkovsky/NoWarDDoS
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRemoteProvider.py
58 lines (48 loc) · 1.66 KB
/
RemoteProvider.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import json
from urllib.parse import unquote
import cachetools.func
import cloudscraper
from settings import get_settings
settings = get_settings()
class RemoteProvider:
def __init__(self, targets=None):
self.targets = [unquote(target) for target in targets] if targets else None
self._proxies = []
self.sites = []
self.scraper = cloudscraper.create_scraper(
browser=settings.BROWSER,
)
def _scrap_json(self, link):
content = self.scraper.get(link).content
try:
data = json.loads(content)
return data
except json.decoder.JSONDecodeError:
return []
@cachetools.func.ttl_cache(ttl=settings.TARGET_UPDATE_RATE)
def get_target_sites(self):
if self.targets:
self.sites = self.targets
else:
self.sites = []
for host in settings.SITES_HOSTS:
try:
data = self._scrap_json(host)
self.sites.extend([site.get("page") for site in data])
except Exception:
pass
return list(set(self.sites))
def _parse_text(self, link):
content = self.scraper.get(link).content.decode("utf-8")
return content.split("\n")
@cachetools.func.ttl_cache(ttl=settings.TARGET_UPDATE_RATE)
def get_proxies(self):
for link in settings.PROXIES_HOSTS:
try:
self._proxies = self._scrap_json(link)
except Exception as e:
raise e
return list(self._proxies)
if __name__ == "__main__":
provider = RemoteProvider()
sites = provider.get_target_sites()