ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/Redgrave/Amazon_ConsilioToFullNamesOveride.py
Revision: 845
Committed: Tue Dec 10 17:16:59 2024 UTC (15 months, 2 weeks ago) by nino.borges
Content type: text/x-python
File size: 2788 byte(s)
Log Message:
Updated this to use RE for the email matching.  too many non-email values mixed in here, as the file from consilio is messy.

File Contents

# User Rev Content
1 nino.borges 843 """
2    
3     Amazon_ConsilioToFullNamesOveride
4    
5     Created by:
6     Emanuel Borges
7     12.5.2024
8    
9     This program will take a spreadsheet, supplied by Consilio, of the formatted names to email addresses table that they use and create a FullNamesOveride file.
10     The columns are normally Raw Entry Formatted Name Priv Entity Email Address
11     Assumes the top row is the header row, which is skips.
12    
13     """
14    
15    
16 nino.borges 845 import os, re
17 nino.borges 843 from win32com.client import Dispatch
18    
19    
20     if __name__ == '__main__':
21     consilioFileName = r"C:\Users\eborges\OneDrive - Redgrave LLP\Documents\Cases\Amazon\_PrivLogQCProcess\Consilio\VEAS-MasterAttorneyList\2024.12.05 - H95472_Amazon VEAS_EmailsInfoForAsterisks.xlsx"
22    
23 nino.borges 845 allPossibleEmailAddressesRegExPattern = r"[\w.+-]+@[\w-]+\.[\w.-]+"
24     consilioFilePath = os.path.split(consilioFileName)[0]
25     fullNamesOverideFileName = os.path.join(consilioFilePath, "FullNameOverides.txt")
26 nino.borges 843
27 nino.borges 845
28 nino.borges 843 outputFile = open(fullNamesOverideFileName,'w')
29     emailAddressMatrix = {}
30    
31     xlApp = Dispatch('Excel.Application')
32     xlBook = xlApp.Workbooks.Open(consilioFileName)
33     sht = xlBook.Worksheets(1)
34    
35     ## find the bottom row
36     bottom = 0
37     while sht.Cells(bottom + 1, 1).Value not in [None, '']:
38     bottom = bottom +1
39     #print(f"first value is {sht.Cells(2, 1).Value}")
40     #print(f"last value is {sht.Cells(bottom, 1).Value}")
41    
42     for rowNumb in range(2,bottom+1):
43     fullName = sht.Cells(rowNumb,2).Value.upper()
44     fullName = fullName.split("*")[0]
45 nino.borges 845 emailAddressCellValue = sht.Cells(rowNumb,3).Value.upper()
46     resultSet = set()
47     results = re.findall(allPossibleEmailAddressesRegExPattern, emailAddressCellValue)
48     if results:
49     for result in results:
50     resultSet.add(result.upper())
51     if len(resultSet) >1:
52     print("ERROR multiple email **unique** email addresses in one item.")
53     print(resultSet)
54     print("\n")
55 nino.borges 843 else:
56 nino.borges 845 emailAddress = resultSet.pop().upper()
57     if emailAddress in list(emailAddressMatrix.keys()):
58     if emailAddressMatrix[emailAddress] == fullName:
59     pass
60     else:
61     print("ERROR: Multiple unique names for the same email address!!!")
62     print(emailAddress, fullName, emailAddressMatrix[emailAddress])
63     else:
64     emailAddressMatrix[emailAddress] = fullName
65     #print(f"{sht.Cells(rowNumb,2).Value} | {sht.Cells(rowNumb,3).Value}")
66 nino.borges 843
67     xlBook.Close()
68    
69     for address in list(emailAddressMatrix.keys()):
70     outputFile.write(f"{address}|{emailAddressMatrix[address]}\n")
71    
72     outputFile.close()
73    
74