| 1 |
nino.borges |
932 |
"""
|
| 2 |
|
|
|
| 3 |
|
|
Amazon_ContractorNamesAnalysis
|
| 4 |
|
|
|
| 5 |
|
|
Created by:
|
| 6 |
|
|
Emanuel Borges
|
| 7 |
|
|
2.13.2025
|
| 8 |
|
|
|
| 9 |
|
|
This program will take a text file of raw contractor names, which are those wiht the [C], and attempt to find a match in the MAL.
|
| 10 |
|
|
|
| 11 |
|
|
"""
|
| 12 |
|
|
|
| 13 |
|
|
|
| 14 |
|
|
|
| 15 |
|
|
import os, re
|
| 16 |
|
|
from collections import namedtuple
|
| 17 |
|
|
import MyCode.Active_prgs.Redgrave.Amazon_NamesNormQC
|
| 18 |
|
|
|
| 19 |
|
|
|
| 20 |
|
|
|
| 21 |
|
|
if __name__ == '__main__':
|
| 22 |
|
|
cleanedDatExportFileName = r"C:\Users\eborges\OneDrive - Redgrave LLP\Documents\Cases\Amazon\_PrivLogQCProcess\20250225-FTC-Retail\export_20250225_230314_Converted.txt"
|
| 23 |
|
|
#cleanedDatExportFileName = r"C:\Users\eborges\OneDrive - Redgrave LLP\Documents\Cases\Amazon\_PrivLogQCProcess\20241215\PrivLogExports\PrivLogExport_20241211_CAAG_Converted.txt"
|
| 24 |
|
|
masterAttorneyListFileName = r"C:\Users\eborges\OneDrive - Redgrave LLP\Documents\Cases\Amazon\_PrivLogQCProcess\Amazon_ Master Attorney List 2025.02.10(20250211-0850).xlsx"
|
| 25 |
|
|
#masterAttorneyListFileName = r"C:\Users\eborges\OneDrive - Redgrave LLP\Documents\Cases\Amazon\_PrivLogQCProcess\Amazon_ Master Attorney List 2024.12.16(20241219-0157).xlsx"
|
| 26 |
|
|
fullNameOveridesFileName = r"C:\Users\eborges\OneDrive - Redgrave LLP\Documents\Cases\Amazon\_PrivLogQCProcess\Consilio\CAAG-MasterAttorneyList\FullNameOverides.txt"
|
| 27 |
|
|
|
| 28 |
|
|
contractorRawValuesFile = r"C:\Users\eborges\OneDrive - Redgrave LLP\Documents\Cases\Amazon\20250204-ContractorAliasReq\RawNames(Cleaned).txt"
|
| 29 |
|
|
|
| 30 |
|
|
rawNamesMatrix = {}
|
| 31 |
|
|
|
| 32 |
|
|
nv = MyCode.Active_prgs.Redgrave.Amazon_NamesNormQC.NamesVerification(cleanedDatExportFileName, masterAttorneyListFileName, fullNameOveridesFileName)
|
| 33 |
|
|
allPossibleEmailAddressesRegExPattern = r"[\w.+-]+@[\w-]+\.[\w.-]+"
|
| 34 |
|
|
|
| 35 |
|
|
|
| 36 |
|
|
## First a named tuple of the possible parts that I can grab from the raw value
|
| 37 |
|
|
ItemValues = namedtuple("ItemValues","lastName firstName emailAddress userName")
|
| 38 |
|
|
|
| 39 |
|
|
|
| 40 |
|
|
contents = open(contractorRawValuesFile).readlines()
|
| 41 |
|
|
for line in contents:
|
| 42 |
|
|
line = line.replace("\n","")
|
| 43 |
|
|
line = line.upper()
|
| 44 |
|
|
## First remove all the [C], because I wont need them
|
| 45 |
|
|
line = line.replace("[C]","")
|
| 46 |
|
|
results = re.findall(allPossibleEmailAddressesRegExPattern, line)
|
| 47 |
|
|
if results:
|
| 48 |
|
|
if len(results) > 1:
|
| 49 |
|
|
print("ERROR: More than one Email address parsed!")
|
| 50 |
|
|
emailAddress = results[0]
|
| 51 |
|
|
userName = emailAddress.split("@")[0]
|
| 52 |
|
|
userName = userName.strip()
|
| 53 |
|
|
else:
|
| 54 |
|
|
emailAddress = ""
|
| 55 |
|
|
userName = ""
|
| 56 |
|
|
if "(" in line:
|
| 57 |
|
|
fullName = line.split("(")[0]
|
| 58 |
|
|
else:
|
| 59 |
|
|
fullName = line
|
| 60 |
|
|
if "," in fullName:
|
| 61 |
|
|
lastName, firstName = fullName.split(",")
|
| 62 |
|
|
else:
|
| 63 |
|
|
firstName, lastName = fullName.split(" ",maxsplit=1)
|
| 64 |
|
|
firstName = firstName.strip()
|
| 65 |
|
|
lastName = lastName.strip()
|
| 66 |
|
|
rawNamesMatrix[line] = ItemValues(lastName, firstName, emailAddress, userName)
|
| 67 |
|
|
|
| 68 |
|
|
|
| 69 |
|
|
for i in list(rawNamesMatrix.keys()):
|
| 70 |
|
|
bestMatchFound = False
|
| 71 |
|
|
partialMatchFound = False
|
| 72 |
|
|
## First check for an email address match and if that matches, dont search anything else
|
| 73 |
|
|
if rawNamesMatrix[i].emailAddress:
|
| 74 |
|
|
personMatch = nv.malPeopleList.search_by_email(rawNamesMatrix[i].emailAddress)
|
| 75 |
|
|
if personMatch:
|
| 76 |
|
|
print(f"{i}|matching email address|{personMatch.unique_attorney_row_number}|{personMatch.first_name}|{personMatch.last_name}|{personMatch.work_email_address}|{personMatch.alt_work_email_address}|{personMatch.is_attorney}")
|
| 77 |
|
|
bestMatchFound = True
|
| 78 |
|
|
if bestMatchFound == False:
|
| 79 |
|
|
personMatch = nv.malPeopleList.return_list_of_matching_values("login",rawNamesMatrix[i].userName)
|
| 80 |
|
|
if personMatch:
|
| 81 |
|
|
for p in personMatch:
|
| 82 |
|
|
print(f"{i}|match on username to loginName|{p.unique_attorney_row_number}|{p.first_name}|{p.last_name}|{p.work_email_address}|{p.alt_work_email_address}|{p.is_attorney}")
|
| 83 |
|
|
partialMatchFound = True
|
| 84 |
|
|
if bestMatchFound == False:
|
| 85 |
|
|
personMatch = nv.malPeopleList.return_list_of_partial_email_matches(rawNamesMatrix[i].emailAddress)
|
| 86 |
|
|
if personMatch:
|
| 87 |
|
|
for p in personMatch:
|
| 88 |
|
|
print(f"{i}|match on a partial email address|{p.unique_attorney_row_number}|{p.first_name}|{p.last_name}|{p.work_email_address}|{p.alt_work_email_address}|{p.is_attorney}")
|
| 89 |
|
|
partialMatchFound = True
|
| 90 |
|
|
## Now let's look for the name matches.
|
| 91 |
|
|
if bestMatchFound == False:
|
| 92 |
|
|
personMatch = nv.malPeopleList.return_list_of_matching_values("last_name",rawNamesMatrix[i].lastName)
|
| 93 |
|
|
if personMatch:
|
| 94 |
|
|
for p in personMatch:
|
| 95 |
|
|
if p.first_name == rawNamesMatrix[i].firstName:
|
| 96 |
|
|
print(f"{i}|first name and last name match|{p.unique_attorney_row_number}|{p.first_name}|{p.last_name}|{p.work_email_address}|{p.alt_work_email_address}|{p.is_attorney}")
|
| 97 |
|
|
else:
|
| 98 |
|
|
print(f"{i}|last name ONLY match|{p.unique_attorney_row_number}|{p.first_name}|{p.last_name}|{p.work_email_address}|{p.alt_work_email_address}|{p.is_attorney}")
|
| 99 |
|
|
partialMatchFound = True
|
| 100 |
|
|
if bestMatchFound == False and partialMatchFound == False:
|
| 101 |
|
|
print(f"{i}|||||||")
|
| 102 |
|
|
#print(i,str(rawNamesMatrix[i]))
|
| 103 |
|
|
|
| 104 |
|
|
|