Merge pull request #860 from cyxae/enh-1355-sort-alphabetically-domains

[enh] Sort alphabetically the domain list
This commit is contained in:
Alexandre Aubin 2020-09-24 17:22:54 +02:00 committed by GitHub
commit f36a17d645
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -59,8 +59,23 @@ def domain_list(exclude_subdomains=False):
parent_domain = domain.split(".", 1)[1]
if parent_domain in result:
continue
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}