[enh] Group same domains and subdomains together

This commit is contained in:
ljf 2020-09-23 00:57:41 +02:00
parent 3cecc7cb30
commit c8e24d898a

View file

@ -59,10 +59,22 @@ def domain_list(exclude_subdomains=False):
parent_domain = domain.split(".", 1)[1]
if parent_domain in result:
continue
result_list.append(".".join(reversed(domain.split("."))))
result_list = sorted(result_list)
for i in range(len(result_list)):
result_list[i] = ".".join(reversed(result_list[i].split(".")))
result_list.append(domain)
def cmp_domain(domain1, domain2):
# Keep the main part of the domain and the extension together
# eg: this.is.an.example.com -> ['example.com', 'an', 'is', 'this']
domain1 = domain1.split('.')
domain2 = domain2.split('.')
domain1[-1] = domain1[-2] + domain1.pop()
domain2[-1] = domain2[-2] + domain2.pop()
domain1 = list(reversed(domain1))
domain2 = list(reversed(domain2))
return cmp(domain1, domain2)
result_list = sorted(result_list, cmp_domain)
return {'domains': result_list}