ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/Redgrave/EndoIGChgReqSysToServer.py
Revision: 780
Committed: Fri Aug 5 02:20:05 2022 UTC (3 years, 7 months ago) by nino.borges
Content type: text/x-python
File size: 2258 byte(s)
Log Message:
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
on the main EndoIGServerAnalyzer program.

File Contents

# Content
1 """
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 #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
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 findAllResultsList = []
40 foundLoc = sht.UsedRange.Cells.Find(serverName)
41 while (foundLoc.Row,foundLoc.Column) not in findAllResultsList:
42 findAllResultsList.append((foundLoc.Row,foundLoc.Column))
43 foundLoc = sht.UsedRange.Cells.FindNext(foundLoc)
44 outputFile.write(serverName + "|")
45 for rowNumb, colNumb in findAllResultsList:
46 outputFile.write("%s|%s"%(sht.Cells(rowNumb,1).value, sht.Cells(rowNumb,2).value))
47 outputFile.write("\n")
48 outputFile.close()
49 xlBook.Close()
50