| 1 |
==== Payment Earth mobile phone report group index creation ====
|
| 2 |
== took a text message report (mms and sms tabs) and created a group index field which takes the phone numbers, sorts them and combines. Inseart the two empty columns first ==
|
| 3 |
== This first one is for the SMS tab, which only has one field with phone numbers in it
|
| 4 |
xlApp = Dispatch('Excel.Application')
|
| 5 |
>>> xlBook = xlApp.Workbooks.Open(r"C:\Test-PY\mobile\Saygin Esener Android.xlsx")
|
| 6 |
>>> sht = xlBook.Worksheets('SMS Messages')
|
| 7 |
>>> for rn in range(3,6318):
|
| 8 |
... vals = sht.Cells(rn,'b').Value
|
| 9 |
... numbOnlyList = re.findall(pattern,vals)
|
| 10 |
... sortedList = list(numbOnlyList)
|
| 11 |
... sortedList.sort()
|
| 12 |
... combinedValsRaw = ""
|
| 13 |
... conversationID = ""
|
| 14 |
... for i in numbOnlyList:
|
| 15 |
... combinedValsRaw = combinedValsRaw + "%s "%i
|
| 16 |
... sht.Cells(rn,'c').Value = combinedValsRaw
|
| 17 |
... for x in sortedList:
|
| 18 |
... conversationID = conversationID + "%s"%x
|
| 19 |
... sht.Cells(rn,'d').Value = conversationID
|
| 20 |
...
|
| 21 |
|
| 22 |
== This second one had two fields with phone numbers in it, so i had to combine first.
|
| 23 |
>>> xlApp = Dispatch('Excel.Application')
|
| 24 |
>>> xlBook = xlApp.Workbooks.Open(r"C:\Test-PY\mobile\Jeff Scanlon iPhone.xlsx")
|
| 25 |
>>> sht = xlBook.Worksheets('MMS Messages')
|
| 26 |
>>> for rn in range(3,235):
|
| 27 |
... vals = sht.Cells(rn,'c').Value
|
| 28 |
... numbOnlyList1 = re.findall(pattern,vals)
|
| 29 |
... vals2 = sht.Cells(rn,'d').Value
|
| 30 |
... numbOnlyList2 = re.findall(pattern,vals2)
|
| 31 |
... numbOnlyList3 = numbOnlyList1 + numbOnlyList2
|
| 32 |
... sortedList = list(numbOnlyList3)
|
| 33 |
... sortedList.sort()
|
| 34 |
... combinedValsRaw = ""
|
| 35 |
... conversationID = ""
|
| 36 |
... for i in numbOnlyList3:
|
| 37 |
... combinedValsRaw = combinedValsRaw + "%s "%i
|
| 38 |
... sht.Cells(rn,'e').Value = combinedValsRaw
|
| 39 |
... for x in sortedList:
|
| 40 |
... conversationID = conversationID + "%s"%x
|
| 41 |
... sht.Cells(rn,'f').Value = conversationID
|
| 42 |
...
|
| 43 |
|
| 44 |
==== End ====
|
| 45 |
|
| 46 |
==== Schneider rename by tags ====
|
| 47 |
== Asked to do an export and then have some custom renaming. ==
|
| 48 |
|
| 49 |
>>> import os
|
| 50 |
>>> outputDir = r"C:\Test-PY\20180425 - Export Req - Modified - 2"
|
| 51 |
>>> for f in os.listdir(r"C:\Test-PY\20180425 - Export Req - Modified"):
|
| 52 |
... fName = os.path.splitext(f)[0]
|
| 53 |
>>> tabMatrix = {}
|
| 54 |
>>> contents = open(r"C:\Test-PY\20180425 - Export Req.dat").readlines()
|
| 55 |
>>> contents[0]
|
| 56 |
'\xfeEVDXID\xfe\x14\xfeBegAttach (Include Family)\xfe\x14\xfeEndAttach\xfe\x14\xfeTab Number\xfe\x14\xfeMD5HASH\xfe\x14\xfeFileName\xfe\x14\xfeDateSent\xfe\x14\xfeEDataFolder\xfe\x14\xfeSource\xfe\x14\xfeAuthor\xfe\x14\xfeProd BegBates\xfe\x14\xfeProd BegBates-AZ\xfe\x14\xfeFileExtension\xfe\x14\xfeProd Volume\xfe\x14\xfeProd Volume-AZ\xfe\x14\xfeVolume\xfe\n'
|
| 57 |
>>> delim = '\x14'
|
| 58 |
>>> quoteChar = '\xfe'
|
| 59 |
>>> contents = contents[1:]
|
| 60 |
>>> len(contents)
|
| 61 |
|
| 62 |
>>> for line in contents:
|
| 63 |
... line = line.replace(quoteChar, "")
|
| 64 |
... line = line.split(delim)
|
| 65 |
... tabMatrix[line[0]] = line[3]
|
| 66 |
... tabMatrix[line[10]] = line[3]
|
| 67 |
... tabMatrix[line[11]] = line[3]
|
| 68 |
...
|
| 69 |
>>> len(tabMatrix.keys())
|
| 70 |
437
|
| 71 |
>>> import shutil
|
| 72 |
|
| 73 |
>>> for f in os.listdir(r"C:\Test-PY\20180425 - Export Req - Modified"):
|
| 74 |
... fName, fExt = os.path.splitext(f)
|
| 75 |
... shutil.copyfile(os.path.join(r"C:\Test-PY\20180425 - Export Req - Modified",f), os.path.join(outputDir,'Tab'+tabMatrix[fName]+ " - " +f))
|
| 76 |
|
| 77 |
==== END ====
|
| 78 |
|
| 79 |
|
| 80 |
==== Glassman filename parse for reunitization ====
|
| 81 |
== Asked to get a better idea of true page count in the met docs by parsing the filename field. ==
|
| 82 |
|
| 83 |
>>> contents = open(r"C:\Test-PY\Glassman\All_MET.dat").readlines()
|
| 84 |
>>> contents[0]
|
| 85 |
'\xfeEVDXID\xfe\x14\xfeEVDXID EndDoc\xfe\x14\xfeBegAttach (Include Family)\xfe\x14\xfeClaim Number\xfe\x14\xfeClaimant\xfe\x14\xfePage Count\xfe\x14\xfeProd PageCount\xfe\x14\xfeDateCreated\xfe\x14\xfeDateLastMod\xfe\x14\xfeSource\xfe\x14\xfeEDataSource\xfe\x14\xfeEDataFolder\xfe\x14\xfeFileName\xfe\x14\xfeProd Volume\xfe\n'
|
| 86 |
>>> contents = contents[1:]
|
| 87 |
>>> delim = '\x14'
|
| 88 |
>>> quoteChar = '\xfe'
|
| 89 |
>>> fNameMatrix = {}
|
| 90 |
>>> missingList = []
|
| 91 |
>>> for line in contents:
|
| 92 |
... line = line.replace(quoteChar,'')
|
| 93 |
... line = line.split(delim)
|
| 94 |
... fileName = line[12]
|
| 95 |
... fileNameParts = fileName.split('_')
|
| 96 |
... if '_' in fileName:
|
| 97 |
... if fileNameParts[-2] in fNameMatrix.keys():
|
| 98 |
... fNameMatrix[fileNameParts[-2]].append(fileName)
|
| 99 |
... else:
|
| 100 |
... fNameMatrix[fileNameParts[-2]] = [fileName,]
|
| 101 |
... else:
|
| 102 |
... missingList.append(line[0])
|
| 103 |
...
|
| 104 |
>>> len(missingList)
|
| 105 |
4124
|
| 106 |
>>> len(fNameMatrix)
|
| 107 |
30169
|
| 108 |
>>> count = 0
|
| 109 |
>>> for x in fNameMatrix.keys():
|
| 110 |
... if len(fNameMatrix[x]) == 1:
|
| 111 |
... count = count + 1
|
| 112 |
...
|
| 113 |
>>> count
|
| 114 |
18824
|