| 1 |
nino.borges |
633 |
"""
|
| 2 |
|
|
|
| 3 |
|
|
EvidoxJSParser
|
| 4 |
|
|
|
| 5 |
|
|
Created by
|
| 6 |
|
|
Emanuel Borges
|
| 7 |
|
|
03.20.2018
|
| 8 |
|
|
|
| 9 |
|
|
A program or just set of methods that will parse and create a new report from the JS.
|
| 10 |
|
|
|
| 11 |
|
|
|
| 12 |
|
|
"""
|
| 13 |
|
|
|
| 14 |
|
|
from win32com.client import Dispatch
|
| 15 |
nino.borges |
647 |
import os
|
| 16 |
nino.borges |
633 |
|
| 17 |
|
|
def GatherColumnTableEnd(sheet, rowStart, colStart):
|
| 18 |
|
|
"""Takes a JS sheet and returns the start and end range of what has data in it."""
|
| 19 |
|
|
right = colStart
|
| 20 |
|
|
while sheet.Cells(rowStart, right + 1).Value not in [None,""]:
|
| 21 |
|
|
right = right +1
|
| 22 |
|
|
|
| 23 |
|
|
colEnd = right
|
| 24 |
|
|
|
| 25 |
|
|
return colStart, colEnd
|
| 26 |
|
|
|
| 27 |
|
|
def GatherRowTableEnd(sheet, rowStart, col):
|
| 28 |
|
|
"""using only the col field, will test all rows, starting at rowstart and returns the end row"""
|
| 29 |
|
|
bottom = rowStart
|
| 30 |
|
|
while sheet.Cells(bottom + 1, col).Value not in [None, '']:
|
| 31 |
|
|
bottom = bottom +1
|
| 32 |
|
|
|
| 33 |
|
|
rowEnd = bottom
|
| 34 |
|
|
return rowEnd
|
| 35 |
|
|
|
| 36 |
nino.borges |
647 |
def ProcessSheet(sheetObj, acceptedFieldsList, acceptedHeadderColor, mediaLogHeadderRow, targetxlBook, targetSheetNumb, caseName, rowAboveOveride = False):
|
| 37 |
|
|
"""The main processor that takes a sheet and processes it into a new sheet. Returns 1 if sucesful and None if not."""
|
| 38 |
|
|
mediaLogJobNumberColumn = None
|
| 39 |
|
|
mediaLogColSizeMatrix = {}
|
| 40 |
|
|
|
| 41 |
|
|
## Unhide all hidden rows. Set to 10,000 rows for now.
|
| 42 |
|
|
sheetObj.Rows('1:10000').Hidden = False
|
| 43 |
|
|
sheetObj.Rows.AutoFit()
|
| 44 |
|
|
|
| 45 |
|
|
## Get a list of the colums that you should grab based on the testing
|
| 46 |
|
|
sheetFieldsToGrab = []
|
| 47 |
|
|
colStart,colEnd = GatherColumnTableEnd(sheetObj,mediaLogHeadderRow,1)
|
| 48 |
|
|
for i in range(colEnd):
|
| 49 |
|
|
i = i + 1
|
| 50 |
|
|
#print "Testing %s"%i
|
| 51 |
|
|
#print "color is %d"% sht.Cells(mediaLogHeadderRow,i).Interior.ColorIndex
|
| 52 |
|
|
## First test the color
|
| 53 |
|
|
if sheetObj.Cells(mediaLogHeadderRow,i).Interior.ColorIndex == acceptedHeadderColor:
|
| 54 |
|
|
## Then test that the test is in the approved list
|
| 55 |
|
|
cellText = sheetObj.Cells(mediaLogHeadderRow,i).Value
|
| 56 |
|
|
if cellText in acceptedFieldsList:
|
| 57 |
|
|
sheetFieldsToGrab.append(i)
|
| 58 |
|
|
mediaLogColSizeMatrix[i] = sheetObj.Cells(mediaLogHeadderRow,i).ColumnWidth
|
| 59 |
|
|
## Try to find the Job Number field too
|
| 60 |
|
|
if cellText == acceptedFieldsList[0]:
|
| 61 |
|
|
mediaLogJobNumberColumn = i
|
| 62 |
|
|
print sheetFieldsToGrab
|
| 63 |
|
|
|
| 64 |
|
|
## Using the jobNumber column, gather the highest row number
|
| 65 |
|
|
if mediaLogJobNumberColumn:
|
| 66 |
|
|
rowEnd = GatherRowTableEnd(sheetObj, mediaLogHeadderRow, mediaLogJobNumberColumn)
|
| 67 |
|
|
print "End row is %d"% rowEnd
|
| 68 |
|
|
#targetxlBook = xlApp.Workbooks.Add()
|
| 69 |
|
|
targetSht = targetxlBook.Worksheets(targetSheetNumb)
|
| 70 |
|
|
|
| 71 |
|
|
## First let's set a starting column on the target
|
| 72 |
|
|
targetColumnStart = 2
|
| 73 |
|
|
|
| 74 |
|
|
if rowAboveOveride:
|
| 75 |
|
|
mediaLogHeadderRow = mediaLogHeadderRow -1
|
| 76 |
|
|
for fieldNumber in sheetFieldsToGrab:
|
| 77 |
|
|
targetMediaLogHeadderRow = mediaLogHeadderRow-mediaLogHeadderRow +3
|
| 78 |
|
|
targetRowEnd = rowEnd-mediaLogHeadderRow + 1
|
| 79 |
|
|
sheetObj.Range(sheetObj.Cells(mediaLogHeadderRow,fieldNumber),sheetObj.Cells(rowEnd,fieldNumber)).Copy(targetSht.Range(targetSht.Cells(targetMediaLogHeadderRow,targetColumnStart),targetSht.Cells(targetRowEnd,targetColumnStart)))
|
| 80 |
|
|
#targetSht.Columns.AutoFit()
|
| 81 |
|
|
targetSht.Cells(targetMediaLogHeadderRow,targetColumnStart).ColumnWidth = mediaLogColSizeMatrix[fieldNumber]
|
| 82 |
|
|
|
| 83 |
|
|
targetColumnStart = targetColumnStart + 1
|
| 84 |
|
|
|
| 85 |
|
|
## Set the pretty case name at the top of the media log
|
| 86 |
|
|
targetSht.Cells(1,2).Value = "%s %s"% (caseName, sheetObj.Name)
|
| 87 |
|
|
targetSht.Cells(1,2).Font.Name = "Calibri"
|
| 88 |
|
|
targetSht.Cells(1,2).Font.Size = 16
|
| 89 |
|
|
targetSht.Name = sheetObj.Name
|
| 90 |
|
|
return 1
|
| 91 |
|
|
else:
|
| 92 |
|
|
print "ERROR: Not able to locate job number column!!"
|
| 93 |
|
|
return None
|
| 94 |
nino.borges |
633 |
|
| 95 |
|
|
if __name__ == '__main__':
|
| 96 |
nino.borges |
647 |
|
| 97 |
|
|
version = 'v1.01'
|
| 98 |
|
|
|
| 99 |
nino.borges |
633 |
xlApp = Dispatch('Excel.Application')
|
| 100 |
|
|
## Turn off any messages about saving over existing target files.
|
| 101 |
|
|
xlApp.DisplayAlerts = False
|
| 102 |
|
|
|
| 103 |
|
|
## matrix of casename, (sourceJS, targetJS)
|
| 104 |
nino.borges |
647 |
## reportsToCreate = {'Bielins - Bennardo':
|
| 105 |
|
|
## (r"C:\Test-PY\liveTest\Bielins-Bennardo-Job Summary.xlsx",r"C:\Test-PY\liveTest\Bielins - BennardoTESTJSLiveReport.xlsx"),
|
| 106 |
|
|
## 'SharkNinja - Keurig':
|
| 107 |
|
|
## (r"C:\Test-PY\liveTest\SharkNinja-Keurig-Job Summary.xlsx",r"C:\Test-PY\liveTest\SharkNinja - KeurigTESTJSLiveReport.xlsx"),
|
| 108 |
|
|
## 'Dairy Farmers-Litigation':
|
| 109 |
|
|
## (r"C:\Test-PY\liveTest\Dairy Farmers-Litigation-Job Summary.xlsx",r"C:\Test-PY\liveTest\Dairy Farmers-LitigationTESTJSLiveReport.xlsx")}
|
| 110 |
nino.borges |
633 |
|
| 111 |
|
|
reportsToCreate = {'I Grace Productions':
|
| 112 |
|
|
(r"\\iadcifs01\job\Lamb Barnosky\I Grace Productions\I Grace Productions--Job Summary.xlsx",r"L:\__People\Emanuel\MCP3_Temp\I Grace Productions-JS-LiveReport.xlsx"),
|
| 113 |
|
|
'McLaughlin Northrup - McDonald Fracassa':
|
| 114 |
nino.borges |
647 |
(r"\\Bluearc01\jobs\Murphy King\McLaughlin Northup-McDonald Fracassa\McLaughlin Northrup-McDonald Fracassa-Job Summary.xlsx",r"L:\__People\Emanuel\MCP3_Temp\McLaughlin Northrup - McDonald Fracassa-JS-LiveReport.xlsx"),
|
| 115 |
|
|
'Dairy Farmers - Litigation':
|
| 116 |
|
|
(r"\\iadcifs01\job\Nystrom Beckman\Dairy Farmers-Litigation\Dairy Farmers-Litigation-Job Summary.xlsx",r"L:\__People\Emanuel\MCP3_Temp\Dairy Farmers-Litigation-JS-LiveReport.xlsx")}
|
| 117 |
|
|
|
| 118 |
|
|
acceptedSheetNames = [u'Media Log',u'Outgoing Productions',u'Incoming Productions']
|
| 119 |
nino.borges |
633 |
|
| 120 |
nino.borges |
647 |
acceptedMediaLogFieldsList = [u'Evidox Job Number', u'Evidox Media ID', u'Media Type', u'Disk Label - Folder / File name', u'Total File Count (# of Files Received)', u'Extracted Filesize (GB)', u'Serial Number', u'Notes', u'Custodian(s)\nREQUIRED', u'Media Received', u'Media Returned']
|
| 121 |
|
|
acceptedMediaLogHeadderColor = 2
|
| 122 |
|
|
mediaLogHeadderRow = 15
|
| 123 |
|
|
|
| 124 |
|
|
acceptedOProdFieldsList = [u'Evidox Job Number', u'Source / Criteria', u'Total Docs Requested for Production', u'Total Exclusions', u'Total Docs Produced',u'Total Docs Produced with Images',u'Total Pages Produced with Images',u'Total Docs Produced Natively',u'Bates Range',u'Docs Requiring',u'Total Pages',u'Unsupported Docs with Placeholders',u'Native Docs with Placeholders',u'Docs Requiring',u'Docs Errored',u'Total Docs',u'Total Pages',u'Opposing Production Volume',u'Opposing Native Production Volume',u'Client Volume',u'Date Delivered',u'Notes']
|
| 125 |
|
|
acceptedOProdHeadderColor = 20
|
| 126 |
|
|
oProdHeadderRow = 3
|
| 127 |
|
|
|
| 128 |
|
|
acceptedIProdFieldsList = [u'Evidox Job Number',u'Evidox Media ID',u'Total Docs Received',u'Total Images / Pages Received',u'Total Text Files Received',u'Total Natives Received',u'Bates / Production Control Number Range(s) ',u'Load Files Received (list extensions)',u'Metadata Received (Y/N)',u'Attachment Info Received (Y/N)',u'Volume',u'Date Delivered',u'Docs Requiring',u'Docs Errored / Excluded',u'Total Docs',u'Total Pages',u'Docs Requiring',u'Docs Errored / Excluded',u'Total Docs',u'Total Pages']
|
| 129 |
|
|
acceptedIProdHeadderColor = 40
|
| 130 |
|
|
iProdHeadderRow = 3
|
| 131 |
|
|
|
| 132 |
|
|
|
| 133 |
nino.borges |
633 |
for reportCaseItem in reportsToCreate.keys():
|
| 134 |
|
|
caseName = reportCaseItem
|
| 135 |
|
|
sourceSpreadsheetPath,targetSpreadsheet = reportsToCreate[reportCaseItem]
|
| 136 |
|
|
|
| 137 |
nino.borges |
647 |
print "Performing modDate test on %s..."%caseName
|
| 138 |
|
|
sourceModifiedDTT = os.stat(sourceSpreadsheetPath)[8]
|
| 139 |
|
|
if os.path.exists(targetSpreadsheet):
|
| 140 |
|
|
targetModifiedDTT = os.stat(targetSpreadsheet)[8]
|
| 141 |
|
|
else:
|
| 142 |
|
|
targetModifiedDTT = 0
|
| 143 |
|
|
if sourceModifiedDTT > targetModifiedDTT:
|
| 144 |
|
|
print "Source has been modified."
|
| 145 |
nino.borges |
633 |
|
| 146 |
nino.borges |
647 |
print "Now processing %s..."% caseName
|
| 147 |
nino.borges |
633 |
|
| 148 |
nino.borges |
647 |
xlBook = xlApp.Workbooks.Open(sourceSpreadsheetPath)
|
| 149 |
|
|
#xlBook = xlApp.Workbooks.Open(r"\\iadcifs01\job\Lamb Barnosky\I Grace Productions\I Grace Productions--Job Summary.xlsx")
|
| 150 |
|
|
#targetSpreadsheet = r"C:\Test-PY\liveTest\OutputJSReport.xlsx"
|
| 151 |
nino.borges |
633 |
|
| 152 |
nino.borges |
647 |
## First lets create a matrix of the sheets to be grabbed from this source
|
| 153 |
|
|
acceptedSheetMatrix = {}
|
| 154 |
|
|
for i in range(xlBook.Sheets.Count):
|
| 155 |
|
|
if xlBook.Sheets(i+1).Name in acceptedSheetNames:
|
| 156 |
|
|
acceptedSheetMatrix[xlBook.Sheets(i+1).Name] = i+1
|
| 157 |
|
|
if acceptedSheetMatrix:
|
| 158 |
|
|
## Only save if at least one of the sheets get created.
|
| 159 |
|
|
atleastOneSheetCreated = False
|
| 160 |
nino.borges |
633 |
|
| 161 |
nino.borges |
647 |
targetSheetNumb = 1
|
| 162 |
|
|
targetxlBook = xlApp.Workbooks.Add()
|
| 163 |
|
|
#for sheetName in acceptedSheetMatrix.keys():
|
| 164 |
|
|
## Eventually make this an object but for now you need control over the properties passed to ProcessSheet and cant just loop through
|
| 165 |
|
|
if u'Media Log' in acceptedSheetMatrix.keys():
|
| 166 |
|
|
sheetResultCode = ProcessSheet(xlBook.Worksheets(acceptedSheetMatrix[u'Media Log']), acceptedMediaLogFieldsList, acceptedMediaLogHeadderColor, mediaLogHeadderRow,targetxlBook, targetSheetNumb, caseName)
|
| 167 |
|
|
if sheetResultCode:
|
| 168 |
|
|
targetSheetNumb = targetSheetNumb + 1
|
| 169 |
|
|
atleastOneSheetCreated = True
|
| 170 |
|
|
|
| 171 |
|
|
if u'Outgoing Productions' in acceptedSheetMatrix.keys():
|
| 172 |
|
|
ProcessSheet(xlBook.Worksheets(acceptedSheetMatrix[u'Outgoing Productions']), acceptedOProdFieldsList, acceptedOProdHeadderColor, oProdHeadderRow, targetxlBook, targetSheetNumb, caseName, True)
|
| 173 |
|
|
if sheetResultCode:
|
| 174 |
|
|
targetSheetNumb = targetSheetNumb + 1
|
| 175 |
|
|
atleastOneSheetCreated = True
|
| 176 |
nino.borges |
633 |
|
| 177 |
nino.borges |
647 |
if u'Incoming Productions' in acceptedSheetMatrix.keys():
|
| 178 |
|
|
ProcessSheet(xlBook.Worksheets(acceptedSheetMatrix[u'Incoming Productions']), acceptedIProdFieldsList, acceptedIProdHeadderColor, iProdHeadderRow, targetxlBook, targetSheetNumb, caseName, True)
|
| 179 |
|
|
if sheetResultCode:
|
| 180 |
|
|
targetSheetNumb = targetSheetNumb + 1
|
| 181 |
|
|
atleastOneSheetCreated = True
|
| 182 |
|
|
|
| 183 |
|
|
if atleastOneSheetCreated:
|
| 184 |
|
|
targetxlBook.SaveAs(targetSpreadsheet)
|
| 185 |
|
|
targetxlBook.Close()
|
| 186 |
|
|
else:
|
| 187 |
|
|
targetxlBook.Close(SaveChanges=False)
|
| 188 |
|
|
print "%s Processed. Closing that spreadsheet."% caseName
|
| 189 |
|
|
xlBook.Close(SaveChanges=False)
|
| 190 |
|
|
else:
|
| 191 |
|
|
print "Source hasnt been modified. Skipping."
|
| 192 |
|
|
|
| 193 |
|
|
|
| 194 |
|
|
|
| 195 |
|
|
#sht = xlBook.Worksheets(1)
|
| 196 |
|
|
#acceptedFieldsList = [u'Evidox Job Number', u'Evidox Media ID', u'Media Type', u'Disk Label - Folder / File name', u'Total File Count (# of Files Received)', u'Extracted Filesize (GB)', u'Serial Number', u'Notes', u'Custodian(s)\nREQUIRED', u'Media Received', u'Media Returned']
|
| 197 |
|
|
#acceptedHeadderColor = 2
|
| 198 |
|
|
|
| 199 |
|
|
#mediaLogHeadderRow = 15
|
| 200 |
|
|
|
| 201 |
nino.borges |
633 |
|
| 202 |
nino.borges |
647 |
|
| 203 |
nino.borges |
633 |
|