| 1 |
nino.borges |
742 |
#### A simple program to combine the TO and FROM for slack messages so thatyou can create the
|
| 2 |
|
|
#### Remote Party field. also propagates this to the children
|
| 3 |
|
|
|
| 4 |
|
|
### This is version 3 where we do the same RE but this time we use more logic as to which should and shouldnt populate the remote party field.
|
| 5 |
|
|
>>> import re
|
| 6 |
|
|
|
| 7 |
|
|
>>> matrix = {}
|
| 8 |
|
|
>>> for line in contents:
|
| 9 |
|
|
... line = line.replace("\n","")
|
| 10 |
|
|
... line = line.replace("\xfe","")
|
| 11 |
|
|
... rawList = re.findall("<[A-Z a-z 0-9]+>",line)
|
| 12 |
|
|
... line = line.split("\x14")
|
| 13 |
|
|
... tempMatrix = {}
|
| 14 |
|
|
... for x in rawList:
|
| 15 |
|
|
... tempMatrix[x] = 1
|
| 16 |
|
|
... catList = tempMatrix.keys()
|
| 17 |
|
|
... catList.sort()
|
| 18 |
|
|
... catList = [item for item in catList if item != '<U1AL36X55>']
|
| 19 |
|
|
... catString = ""
|
| 20 |
|
|
... grp = False
|
| 21 |
|
|
... chnl = False
|
| 22 |
|
|
... for i in catList:
|
| 23 |
|
|
... if i[:2] == '<G':
|
| 24 |
|
|
... grp = i
|
| 25 |
|
|
... if i[:2] == '<C':
|
| 26 |
|
|
... chnl = i
|
| 27 |
|
|
... if grp:
|
| 28 |
|
|
... catString = grp
|
| 29 |
|
|
... elif chnl:
|
| 30 |
|
|
... catString = chnl
|
| 31 |
|
|
... else:
|
| 32 |
|
|
... for y in catList:
|
| 33 |
|
|
... catString = catString + ";" + y
|
| 34 |
|
|
... matrix[line[0]] = catString
|
| 35 |
|
|
... if line[3]:
|
| 36 |
|
|
... attachIDs = line[3].split(";")
|
| 37 |
|
|
... for attachID in attachIDs:
|
| 38 |
|
|
... matrix[attachID] = catString
|
| 39 |
|
|
...
|
| 40 |
|
|
>>> len(matrix.keys())
|
| 41 |
|
|
157505
|
| 42 |
|
|
>>> warning = 0
|
| 43 |
|
|
>>> for i in matrix.keys():
|
| 44 |
|
|
... test = len(matrix[i])
|
| 45 |
|
|
... if test > warning:
|
| 46 |
|
|
... warning = test
|
| 47 |
|
|
...
|
| 48 |
|
|
>>> warning
|
| 49 |
|
|
12
|
| 50 |
|
|
>>> outputFile = open(r"C:\Temp\Lee-Mercer\Slack-RemoteParty-OVERLAY.dat",'w')
|
| 51 |
|
|
>>> outputFile.write("DocumentID|Slack_Remote_Party\n")
|
| 52 |
|
|
>>> test = matrix.keys()
|
| 53 |
|
|
>>> test.sort()
|
| 54 |
|
|
>>> for i in test:
|
| 55 |
|
|
... outputFile.write("%s|%s\n"% (i, matrix[i]))
|
| 56 |
|
|
...
|
| 57 |
|
|
>>> outputFile.close()
|
| 58 |
|
|
|
| 59 |
|
|
### This is version 2 where we are doing the same combine and sort but this time using a RE that only extracts the <code> to the remote party field. Not the final version
|
| 60 |
|
|
>>> import re
|
| 61 |
|
|
|
| 62 |
|
|
>>> matrix = {}
|
| 63 |
|
|
>>> for line in contents:
|
| 64 |
|
|
... line = line.replace("\n","")
|
| 65 |
|
|
... line = line.replace("\xfe","")
|
| 66 |
|
|
... catList = re.findall("<[A-Z a-z 0-9]+>",line)
|
| 67 |
|
|
... line = line.split("\x14")
|
| 68 |
|
|
... catList.sort()
|
| 69 |
|
|
... catString = ""
|
| 70 |
|
|
... for i in catList:
|
| 71 |
|
|
... catString = catString + ";" + i
|
| 72 |
|
|
... matrix[line[0]] = catString
|
| 73 |
|
|
... if line[3]:
|
| 74 |
|
|
... attachIDs = line[3].split(";")
|
| 75 |
|
|
... for attachID in attachIDs:
|
| 76 |
|
|
... matrix[attachID] = catString
|
| 77 |
|
|
...
|
| 78 |
|
|
>>> len(matrix.keys())
|
| 79 |
|
|
157505
|
| 80 |
|
|
>>> warning = 0
|
| 81 |
|
|
>>> for i in matrix.keys():
|
| 82 |
|
|
... test = len(matrix[i])
|
| 83 |
|
|
... if test > warning:
|
| 84 |
|
|
... warning = test
|
| 85 |
|
|
...
|
| 86 |
|
|
>>> warning
|
| 87 |
|
|
48
|
| 88 |
|
|
>>> outputFile = open(r"C:\Temp\Lee-Mercer\Slack-RemoteParty-OVERLAY.dat",'w')
|
| 89 |
|
|
>>> outputFile.write("DocumentID|Slack_Remote_Party\n")
|
| 90 |
|
|
>>> test = matrix.keys()
|
| 91 |
|
|
>>> test.sort()
|
| 92 |
|
|
>>> for i in test:
|
| 93 |
|
|
... outputFile.write("%s|%s\n"% (i, matrix[i]))
|
| 94 |
|
|
...
|
| 95 |
|
|
>>> outputFile.close()
|
| 96 |
|
|
>>>
|
| 97 |
|
|
|
| 98 |
|
|
|
| 99 |
|
|
### This is version 1 where we are using the full field. Not the final version
|
| 100 |
|
|
>>> contents = open(r"C:\Temp\Lee-Mercer\Slack-RemoteParty.dat").readlines()
|
| 101 |
|
|
>>> contents[0]
|
| 102 |
|
|
'\xfeDocument ID\xfe\x14\xfeTO\xfe\x14\xfeFrom\xfe\x14\xfeAttachIDs\xfe\n'
|
| 103 |
|
|
>>> contents = contents[1:]
|
| 104 |
|
|
>>> matrix = {}
|
| 105 |
|
|
>>> for line in contents:
|
| 106 |
|
|
... line = line.replace("\n","")
|
| 107 |
|
|
... line = line.replace("\xfe","")
|
| 108 |
|
|
... line = line.replace('"',"")
|
| 109 |
|
|
... line = line.split("\x14")
|
| 110 |
|
|
... catList = [line[1].replace(";",""),]
|
| 111 |
|
|
... catList.append(line[2].replace(";",""))
|
| 112 |
|
|
... catList.sort()
|
| 113 |
|
|
... catString = ""
|
| 114 |
|
|
... for i in catList:
|
| 115 |
|
|
... catString = catString + ";" + i
|
| 116 |
|
|
... matrix[line[0]] = catString
|
| 117 |
|
|
... if line[3]:
|
| 118 |
|
|
... attachIDs = line[3].split(";")
|
| 119 |
|
|
... for attachID in attachIDs:
|
| 120 |
|
|
... matrix[attachID] = catString
|
| 121 |
|
|
...
|
| 122 |
|
|
>>> len(matrix.keys())
|
| 123 |
|
|
157505
|
| 124 |
|
|
>>> warning = 0
|
| 125 |
|
|
>>> for i in matrix.keys():
|
| 126 |
|
|
... test = len(matrix[i])
|
| 127 |
|
|
... if test > warning:
|
| 128 |
|
|
... warning = test
|
| 129 |
|
|
...
|
| 130 |
|
|
>>> warning
|
| 131 |
|
|
143
|
| 132 |
|
|
>>> outputFile = open(r"C:\Temp\Lee-Mercer\Slack-RemoteParty-OVERLAY.dat",'w')
|
| 133 |
|
|
>>> outputFile.write("DocumentID|Slack_Remote_Party\n")
|
| 134 |
|
|
>>> test = matrix.keys()
|
| 135 |
|
|
>>> test.sort()
|
| 136 |
|
|
>>> for i in test:
|
| 137 |
|
|
... outputFile.write("%s|%s\n"% (i, matrix[i]))
|
| 138 |
|
|
...
|
| 139 |
|
|
>>> outputFile.close() |