HomeHarvest/homeharvest/utils.py

39 lines
1.0 KiB
Python
Raw Permalink Normal View History

import re
2023-09-19 19:13:20 -07:00
def parse_address_one(street_address: str) -> tuple:
2023-09-18 15:42:16 -07:00
if not street_address:
2023-09-19 19:13:20 -07:00
return street_address, "#"
2023-09-18 15:42:16 -07:00
apt_match = re.search(
2023-09-18 15:57:15 -07:00
r"(APT\s*[\dA-Z]+|#[\dA-Z]+|UNIT\s*[\dA-Z]+|LOT\s*[\dA-Z]+|SUITE\s*[\dA-Z]+)$",
2023-09-18 15:42:16 -07:00
street_address,
re.I,
)
if apt_match:
apt_str = apt_match.group().strip()
2023-09-19 19:13:20 -07:00
cleaned_apt_str = re.sub(r"(APT\s*|UNIT\s*|LOT\s*|SUITE\s*)", "#", apt_str, flags=re.I)
2023-09-18 15:42:16 -07:00
2023-09-18 15:57:15 -07:00
main_address = street_address.replace(apt_str, "").strip()
2023-09-18 15:42:16 -07:00
return main_address, cleaned_apt_str
else:
2023-09-19 19:13:20 -07:00
return street_address, "#"
2023-09-18 15:42:16 -07:00
2023-09-19 19:13:20 -07:00
def parse_address_two(street_address: str):
2023-09-18 15:04:34 -07:00
if not street_address:
2023-09-19 19:13:20 -07:00
return "#"
2023-09-18 15:04:54 -07:00
apt_match = re.search(
2023-09-19 19:13:20 -07:00
r"(APT\s*[\dA-Z]+|#[\dA-Z]+|UNIT\s*[\dA-Z]+|LOT\s*[\dA-Z]+|SUITE\s*[\dA-Z]+)$",
2023-09-18 15:04:54 -07:00
street_address,
re.I,
)
2023-09-18 15:04:34 -07:00
if apt_match:
apt_str = apt_match.group().strip()
2023-09-19 19:13:20 -07:00
apt_str = re.sub(r"(APT\s*|UNIT\s*|LOT\s*|SUITE\s*)", "#", apt_str, flags=re.I)
2023-09-18 15:04:34 -07:00
return apt_str
else:
2023-09-19 19:13:20 -07:00
return "#"