| 1 |
nino.borges |
651 |
--- Request to depuplicate two prods, using MD5 hash, but where only the non family memebers get deduplicated. ---
|
| 2 |
|
|
>>> md5DupeMatrix = {}
|
| 3 |
|
|
>>> familyMatrix = {}
|
| 4 |
|
|
>>> contents = open(r"C:\Test-PY\schneider\md5tally.csv").readlines()
|
| 5 |
|
|
>>> contents = contents[1:]
|
| 6 |
|
|
>>> for line in contents:
|
| 7 |
|
|
... line = line.replace("\n","")
|
| 8 |
|
|
... line = line.split("|")
|
| 9 |
|
|
... md5DupeMatrix[line[0]] = line[1]
|
| 10 |
|
|
...
|
| 11 |
|
|
>>> len(md5DupeMatrix.keys())
|
| 12 |
|
|
2750
|
| 13 |
|
|
>>> contents = open(r"C:\Test-PY\schneider\dedupeCombined.dat").readlines()
|
| 14 |
|
|
>>> contents = contents[1:]
|
| 15 |
|
|
>>> len(contents)
|
| 16 |
|
|
14732
|
| 17 |
|
|
>>> for line in contents:
|
| 18 |
|
|
... line = line.replace("\n","")
|
| 19 |
|
|
... line = line.split("|len")
|
| 20 |
|
|
... md5DupeMatrix[line[0]] = line[1]
|
| 21 |
|
|
...
|
| 22 |
|
|
>>> contents[0]
|
| 23 |
|
|
'AZ-PROD_INV0000001\x14AZ-PROD_INV0000001\x14AZ-PROD_INV0000001\x147B608BE628F2F021A033E1B6B3A56F67\x14Copy of X-5-7664 - Risk Register - 10-29-14.xlsx\x14\x14\\01_All Project Documents\\A.) Meeting Minutes\\01_Owner Meeting Minutes\x14AZ Corporation ? Electronic Files Requested by Invensys Systems\x14Lori Watson\n'
|
| 24 |
|
|
>>> for line in contents:
|
| 25 |
|
|
... line = line.replace("\n","")
|
| 26 |
|
|
... line = line.split("\x14")
|
| 27 |
|
|
... if line[1] in familyMatrix.keys():
|
| 28 |
|
|
... familyMatrix[line[1]].append(line[0])
|
| 29 |
|
|
... else:
|
| 30 |
|
|
... familyMatrix[line[1]] = [line[0],]
|
| 31 |
|
|
...
|
| 32 |
|
|
>>> md5DocMatrix = {}
|
| 33 |
|
|
>>> for line in contents:
|
| 34 |
|
|
... line = line.replace("\n","")
|
| 35 |
|
|
... line = line.split("\x14")
|
| 36 |
|
|
... md5DocMatrix[line[0]] = line[3]
|
| 37 |
|
|
...
|
| 38 |
|
|
>>> len(md5DocMatrix.keys())
|
| 39 |
|
|
14732
|
| 40 |
|
|
>>> for parent in familyMatrix.keys():
|
| 41 |
|
|
...
|
| 42 |
|
|
>>> noFamilyList = []
|
| 43 |
|
|
>>> for parent in familyMatrix.keys():
|
| 44 |
|
|
... if len(familyMatrix[parent]) < 2:
|
| 45 |
|
|
... noFamilyList.append(familyMatrix[parent])[0]
|
| 46 |
|
|
...
|
| 47 |
|
|
Traceback (most recent call last):
|
| 48 |
|
|
File "<interactive input>", line 3, in <module>
|
| 49 |
|
|
TypeError: 'NoneType' object has no attribute '__getitem__'
|
| 50 |
|
|
>>> len(noFamilyList)
|
| 51 |
|
|
1
|
| 52 |
|
|
>>> noFamilyList
|
| 53 |
|
|
[['AZ-PROD_INV0006558']]
|
| 54 |
|
|
>>> noFamilyList = []
|
| 55 |
|
|
>>> for parent in familyMatrix.keys():
|
| 56 |
|
|
... if len(familyMatrix[parent]) < 2:
|
| 57 |
|
|
... noFamilyList.append(familyMatrix[parent][0])
|
| 58 |
|
|
...
|
| 59 |
|
|
>>> len(noFamilyList)
|
| 60 |
|
|
7717
|
| 61 |
|
|
>>> noFamilyList[:5]
|
| 62 |
|
|
['AZ-PROD_INV0006558', 'AZ-PROD_INV0006551', 'HANLON_PROD_0011986', 'AZ-PROD_INV0007978', 'AZ-PROD_INV0029104']
|
| 63 |
|
|
>>> for doc in noFamilyList:
|
| 64 |
|
|
... if doc in
|
| 65 |
|
|
>>> noFamilyDupe = []
|
| 66 |
|
|
>>> for doc in noFamilyList:
|
| 67 |
|
|
... if md5DocMatrix[doc] in md5DupeMatrix.keys():
|
| 68 |
|
|
... noFamilyDupe.append(doc)
|
| 69 |
|
|
...
|
| 70 |
|
|
>>> len(noFamilyDupe)
|
| 71 |
|
|
2386
|
| 72 |
|
|
>>> noFamilyDupe[0]
|
| 73 |
|
|
'AZ-PROD_INV0006558'
|
| 74 |
|
|
>>> noFamilyDupe[1000]
|
| 75 |
|
|
'HANLON_PROD_0011356'
|
| 76 |
|
|
>>> outputFile = open(r"C:\Test-PY\schneider\dupsNoFam.txt",'w')
|
| 77 |
|
|
>>> for doc in noFamilyDupe:
|
| 78 |
|
|
... outputFile.write(doc + "\n")
|
| 79 |
|
|
...
|
| 80 |
|
|
>>> outputFile.close() |