ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/eDiiToDAT.py
Revision: 560
Committed: Tue Nov 25 15:56:26 2014 UTC (11 years, 4 months ago) by nino.borges
Content type: text/x-python
File size: 3679 byte(s)
Log Message:
New program to convert eDiii to dat, so that it can be loaded into RL

File Contents

# Content
1 """
2 eDiiToDAT.py
3
4 Created by Emanuel Borges
5 08.22.2014
6
7 This program will take and parse an eDii file and convert it to a dat file, so that it can be loaded into Relativity
8 or Concordance.
9
10 """
11
12 import os
13
14 class ParseDiiFile(object):
15 """This is the main class for the program that parses and converts 1 or multiple files"""
16 def __init__(self):
17 pass
18
19 class HeadderInfo(object):
20 def __init__(self):
21 self.headderRow = ['BegNo']
22
23 def ParseForHeadderInfo(self,diiPath):
24 contents = open(diiPath).readlines()
25 for line in contents:
26 if line[:2] == '@C':
27 line = line.replace("\n","")
28 fieldName = line.split(" ")[1]
29 if fieldName in self.headderRow:
30 pass
31 else:
32 self.headderRow.append(fieldName)
33 def WriteHeadderRow(self,outputFilePath):
34 count = 1
35 outputFile = open(outputFilePath,'w')
36 for i in self.headderRow:
37 outputFile.write(i)
38 if count < len(self.headderRow):
39 outputFile.write("|")
40 else:
41 outputFile.write("\n")
42 count = count + 1
43 outputFile.close()
44
45 class SingleRecord(object):
46 def __init__(self,begno):
47 self.BegNo = begno
48 def ReturnInformation(self,info):
49 data = getattr(self,info)
50 return data
51 def SaveInformation(self,field,info):
52 data = setattr(self,field,info)
53
54
55 if __name__ == '__main__':
56 hi = HeadderInfo()
57 for root, dirs, files in os.walk(r"W:\Manny\Client\DII FILES"):
58 for f in files:
59 if os.path.splitext(f)[1].upper() == ".DII":
60 hi.ParseForHeadderInfo(os.path.join(root,f))
61 hi.WriteHeadderRow(r"W:\Manny\Client\output.dat")
62 count = 0
63 matrix = {}
64 for root, dirs, files in os.walk(r"W:\Manny\Client\DII FILES"):
65 for f in files:
66 if os.path.splitext(f)[1].upper() == ".DII":
67 contents = open(os.path.join(root,f))
68 for line in contents:
69 line = line.replace("\n","")
70 if line[:2] == '@T':
71 begno = line.split("@T")[1]
72 ## I'd like to just use the bates as teh key but what if it exists...
73 count = count+1
74 matrix[count] = SingleRecord(begno)
75
76 elif line[:2] == '@C':
77 field = line.split("@C")[1]
78 field = field.split(" ")[1]
79 field = field.strip()
80 #print field
81 matrix[count].SaveInformation(field,line.split(field)[1])
82 recordList = matrix.keys()
83 recordList.sort()
84 outputFile = open(r"W:\Manny\Client\output.dat",'a')
85
86 for i in recordList:
87 cnt = 1
88 for field in hi.headderRow:
89 try:
90 outputFile.write(matrix[i].ReturnInformation(field).strip())
91 if cnt < len(hi.headderRow):
92 outputFile.write("|")
93 else:
94 outputFile.write("\n")
95 cnt = cnt + 1
96 except:
97 if cnt < len(hi.headderRow):
98 outputFile.write("|")
99 else:
100 outputFile.write("\n")
101 cnt = cnt +1
102 #outputFile.writelines(matrix[i].__dict__)
103 #outputFile.write("\n")
104 outputFile.close()
105