| 1 |
nino.borges |
780 |
"""
|
| 2 |
|
|
|
| 3 |
|
|
EndoIGChgReqSysToServer
|
| 4 |
|
|
|
| 5 |
|
|
Created by:
|
| 6 |
|
|
Emanuel Borges
|
| 7 |
|
|
08.04.2022
|
| 8 |
|
|
|
| 9 |
|
|
Using COM, this program will create a simplified txt file with rows from the Change Request Exports spreadsheets that hit on our server names. I'll then ingest this
|
| 10 |
|
|
on the main EndoIGServerAnalyzer program.
|
| 11 |
|
|
|
| 12 |
|
|
"""
|
| 13 |
|
|
|
| 14 |
|
|
from win32com.client import Dispatch
|
| 15 |
|
|
|
| 16 |
|
|
if __name__ == '__main__':
|
| 17 |
|
|
outputFileName = r"C:\Test_Dir\serverToExcel.txt"
|
| 18 |
|
|
|
| 19 |
|
|
xlSpreadSheetFileName = r"C:\Users\eborges\Documents\Cases\Endo\20220715 - IG Projects\4 - Develop Identification Process to Inventory NCDS stored in Endo IT\_fromEndo\_otherInformation\ServiceNow Change Requests Jan 30 2020 to July 28 2022 - Copy.xlsx"
|
| 20 |
nino.borges |
783 |
win2kServersFile = r"C:\Users\eborges\Documents\Cases\Endo\20220715 - IG Projects\4 - Develop Identification Process to Inventory NCDS stored in Endo IT\_fromEndo\_csv\Win8Servers_NOFilter.csv"
|
| 21 |
|
|
#win2kServersFile = r"C:\Users\eborges\Documents\Cases\Endo\20220715 - IG Projects\4 - Develop Identification Process to Inventory NCDS stored in Endo IT\_fromEndo\_csv\Test.csv"
|
| 22 |
nino.borges |
780 |
|
| 23 |
|
|
serverNamesMatrix = {}
|
| 24 |
|
|
contents = open(win2kServersFile).readlines()
|
| 25 |
|
|
contents = contents[1:]
|
| 26 |
|
|
for line in contents:
|
| 27 |
|
|
line = line.replace("\n","")
|
| 28 |
|
|
line = line.split("|")
|
| 29 |
|
|
serverNamesMatrix[line[0].upper()] = 1
|
| 30 |
|
|
|
| 31 |
|
|
print("There are %s unique server names."%len(list(serverNamesMatrix.keys())))
|
| 32 |
|
|
outputFile = open(outputFileName,'w')
|
| 33 |
|
|
|
| 34 |
|
|
xlApp = Dispatch('Excel.Application')
|
| 35 |
|
|
xlBook = xlApp.Workbooks.Open(xlSpreadSheetFileName)
|
| 36 |
|
|
sht = xlBook.Worksheets(1)
|
| 37 |
|
|
for serverName in list(serverNamesMatrix.keys()):
|
| 38 |
|
|
print("Now processing %s..."% serverName)
|
| 39 |
nino.borges |
783 |
#outputFile.write(serverName + "|")
|
| 40 |
nino.borges |
780 |
findAllResultsList = []
|
| 41 |
|
|
foundLoc = sht.UsedRange.Cells.Find(serverName)
|
| 42 |
nino.borges |
783 |
if foundLoc:
|
| 43 |
|
|
while (foundLoc.Row,foundLoc.Column) not in findAllResultsList:
|
| 44 |
|
|
findAllResultsList.append((foundLoc.Row,foundLoc.Column))
|
| 45 |
|
|
foundLoc = sht.UsedRange.Cells.FindNext(foundLoc)
|
| 46 |
|
|
uniqueRows = set()
|
| 47 |
|
|
for rowNumb, colNumb in findAllResultsList:
|
| 48 |
|
|
uniqueRows.add(rowNumb)
|
| 49 |
|
|
uniqueRows = list(uniqueRows)
|
| 50 |
|
|
uniqueRows.sort()
|
| 51 |
|
|
for uniqueRowNumb in uniqueRows:
|
| 52 |
|
|
outputFile.write("%s|%s|%s|%s|%s|%s\n"%(serverName,sht.Cells(uniqueRowNumb,1).value, sht.Cells(uniqueRowNumb,2).value, sht.Cells(uniqueRowNumb,12).value, sht.Cells(uniqueRowNumb,36).value, sht.Cells(uniqueRowNumb,114).value))
|
| 53 |
|
|
else:
|
| 54 |
|
|
outputFile.write(serverName + "||||\n")
|
| 55 |
|
|
#outputFile.write("\n")
|
| 56 |
nino.borges |
780 |
outputFile.close()
|
| 57 |
|
|
xlBook.Close()
|
| 58 |
|
|
|