handle bom in phone number field

This commit is contained in:
Kenneth Kehl
2024-02-01 12:01:29 -08:00
parent c6ef8a1259
commit 82dd29d457
2 changed files with 11 additions and 8 deletions

View File

@@ -105,24 +105,20 @@ def extract_phones(job):
current_app.logger.info(f"HEADERS {first_row}")
phone_index = 0
for item in first_row:
if item.lower() == "phone number":
# Note: may contain a BOM and look like \ufeffphone number
if "phone number" in item.lower():
break
phone_index = phone_index + 1
phones = {}
job_row = 0
for row in job:
row = row.split(",")
# TODO WHY ARE WE CALCULATING PHONE INDEX IN THE LOOP?
phone_index = 0
for item in first_row:
if item.lower() == "phone number":
break
phone_index = phone_index + 1
current_app.logger.info(f"PHONE INDEX IS NOW {phone_index}")
current_app.logger.info(f"LENGTH OF ROW IS {len(row)}")
if phone_index >= len(row):
phones[job_row] = "Error: can't retrieve phone number"
current_app.logger.error("Corrupt csv file, missing columns job_id {job_id} service_id {service_id}")
current_app.logger.error("Corrupt csv file")
else:
my_phone = row[phone_index]
my_phone = re.sub(r"[\+\s\(\)\-\.]*", "", my_phone)