Split email list out again

The list of email domains is a different list from the list of all
government domains. And because the list of all government domains is
really long now, it could be unnecessarily slow to search through when
(a lot of the time) all we care about is whether the email address ends
with `.gov.uk`.
This commit is contained in:
Chris Hill-Scott
2018-02-06 16:26:02 +00:00
parent 8b739ddc50
commit 5404107842
2 changed files with 38 additions and 4 deletions

30
app/email_domains.yml Normal file
View File

@@ -0,0 +1,30 @@
---
- gov.uk
- mod.uk
- mil.uk
- ddc-mod.org
- slc.co.uk
- gov.scot
- parliament.uk
- nhs.uk
- nhs.net
- police.uk
- dclgdatamart.co.uk
- ucds.email
- naturalengland.org.uk
- hmcts.net
- scotent.co.uk
- assembly.wales
- cjsm.net
- cqc.org.uk
- bl.uk
- stfc.ac.uk
- wmfs.net
- bbsrc.ac.uk
- acas.org.uk
- gov.wales
- biglotteryfund.org.uk
- marinemanagement.org.uk
- britishmuseum.org
- derrystrabane.com
- highwaysengland.co.uk

View File

@@ -284,7 +284,7 @@ def get_help_argument():
def is_gov_user(email_address):
try:
GovernmentDomain(email_address)
GovernmentDomain(email_address, domain_list='email_domain_names')
return True
except NotGovernmentDomain:
return False
@@ -447,17 +447,21 @@ class GovernmentDomain:
domains = yaml.safe_load(domains)
domain_names = sorted(domains.keys(), key=len)
def __init__(self, email_address_or_domain):
with open('{}/email_domains.yml'.format(_dir_path)) as email_domains:
email_domain_names = yaml.safe_load(email_domains)
def __init__(self, email_address_or_domain, domain_list='domain_names'):
try:
self._match = next(filter(
self.get_matching_function(email_address_or_domain),
self.domain_names,
getattr(self, domain_list),
))
except StopIteration:
raise NotGovernmentDomain()
self.owner, self.sector, self.agreement_signed = self._get_details_of_domain()
if domain_list == 'domain_names':
self.owner, self.sector, self.agreement_signed = self._get_details_of_domain()
@staticmethod
def get_matching_function(email_address_or_domain):