-
Notifications
You must be signed in to change notification settings - Fork 0
/
DomainsHunter.py
82 lines (70 loc) · 3.05 KB
/
DomainsHunter.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import configparser
from re import match
from requests import get
CONFIG = configparser.ConfigParser()
CONFIG.read("config.ini")
class DomainsHunter:
@staticmethod
def search_keyword(keyword: str, category=True) -> list:
if category is False:
category = "&category=search_trends"
else:
category = "&category=all"
response = get(
f"https://api.reg.ru/api/regru2/domain/get_suggest?output_content_type=plain&use_hyphen=0"
f"&username={CONFIG['regru_public_creds']['username']}&password={CONFIG['regru_public_creds']['username']}&word={keyword}" + category
).json()
out_data = []
for domain in response['answer']['suggestions']:
for tld in domain['avail_in']:
out_data.append(f"{domain['name']}.{tld}")
return out_data
@staticmethod
def get_deleted(date: str = "", pr=None, len_domain=None) -> list:
if date:
assert match(r"^\d\d\d\d-\d\d-\d\d$", date)
date = f"&deleted_from={date}"
response = get(
f"https://api.reg.ru/api/regru2/domain/get_deleted?password={CONFIG['regru_public_creds']['username']}&username={CONFIG['regru_public_creds']['password']}&hidereg=1" + date
).json()
out_data = []
for domain in response['answer']['domains']:
if pr is not None or pr is not None:
if domain['google_pr'] >= pr or domain['yandex_tic'] >= pr:
if len_domain is not None:
if len(domain['domain_name'].split(".")[0]) <= len_domain:
out_data.append(domain)
else:
out_data.append(domain)
else:
if len_domain is not None:
if len(domain['domain_name'].split(".")[0]) <= len_domain:
out_data.append(domain)
else:
out_data.append(domain)
return out_data
@staticmethod
def deleted_keyword(date: str, keyword: str) -> list:
assert match(r"^\d\d\d\d-\d\d-\d\d$", date)
get_deleted = DomainsHunter.get_deleted(date)
out = []
for domain in get_deleted:
if domain['domain_name'].find(keyword) != -1:
out.append(domain['domain_name'])
return out
@staticmethod
def check_availability(domains: list) -> list:
assert isinstance(domains, list)
domains_list = [
{'dname': domain} for domain in domains
]
domains_list = str(domains_list).replace("'", '"')
response = get(
'https://api.reg.ru/api/regru2/domain/check?input_data={"domains":'
+ domains_list + "}&input_format=json" + f"&password={CONFIG['regru_public_creds']['password']}&username={CONFIG['regru_public_creds']['username']}"
).json()
out_data = []
for domain in response['answer']['domains']:
if domain['result'] == "Available":
out_data.append(domain['dname'])
return out_data