Added EINData dataclass with compare function & scoring

master
Griffiths Lott 3 years ago
parent 369bc2fd14
commit f9748d9662
  1. 63
      EINService.py

@ -10,26 +10,55 @@ from pprint import pprint as prt
SAMPLE_EIN = "59-1571026" SAMPLE_EIN = "59-1571026"
@dataclass @dataclass
class EINResult: class EINData:
found: bool
match: bool def __init__(self, ein: str, buinessName: str, address1: str, city:str, state:str, zip: str, phone: str) -> None:
businessName: str if re.search("\d{2}(-|)\d{7}", str(ein)) == None:
address: str try: raise Exception(f"Invalid EIN: {ein}")
city: str except Exception as e:
state: zip print(e)
return None
self.ein = ein.strip().replace('-','')
self.buinessName = buinessName.lower().strip()
self.address1 = address1.lower().strip()
self.city = city.lower().strip()
self.state = state.lower().strip()
self.phone = phone.strip().replace('-','').replace('(',"").replace(')','').replace('+','')
try:
self.zip = int(zip.replace('-','').strip())
except:
print(f"Invalid ZIP code: {zip}")
def get_ein(self) -> str:
return f"{self.ein[0:2]}-{self.ein[2:]}"
def compare(self, otherEIN: 'EINData') -> dict:
compareDict = {
"buinessName" : True if self.buinessName == otherEIN.businessName else False,
"address" : True if self.address1 == otherEIN.address1 else False,
"city": True if self.city == otherEIN.city else False,
"state": True if self.state == otherEIN.state else False,
"zip" : True if self.zip == otherEIN.zip else False
}
score = 0
for v in compareDict.values():
score += 1 if v else 0
compareDict["score"] = score
return compareDict
class EINService(ABC): class EINService(ABC):
@classmethod @classmethod
@abstractmethod @abstractmethod
def search_ein(self, ein: str) -> EINResult: def search_ein(self, ein: str) -> EINData:
""" """
Takes a an ein and returns information from a search using the service Takes a an ein and returns information from a search using the service
""" """
@classmethod @classmethod
@abstractmethod @abstractmethod
def search_eins(self, eins: list[EINResult]): def search_eins(self, eins: list[EINData]):
""" """
""" """
@ -58,12 +87,20 @@ class EINTaxIDService(EINService):
text = soup.text.splitlines()[4] text = soup.text.splitlines()[4]
data = self._parse_return(text) data = self._parse_return(text)
return data return EINData(
ein,
def search_eins(eins: list[EINResult]): data["company"],
data["address1"],
data["city"],
data["state"],
data["zip"],
data["phone"]
)
def search_eins(eins: list[EINData]):
pass pass
def _parse_return(self, content: str): def _parse_return(self, content: str) -> EINData:
m = re.search("EIN Number:", content) m = re.search("EIN Number:", content)
company = content[0:m.start()].strip() company = content[0:m.start()].strip()

Loading…
Cancel
Save