ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/RandomCodeRequests/CodeforFeliciaProj_20090520.txt
Revision: 8
Committed: Sat May 5 04:21:19 2012 UTC (13 years, 10 months ago) by ninoborges
Content type: text/plain
File size: 3269 byte(s)
Log Message:
Initial Import

File Contents

# User Rev Content
1 ninoborges 8 Felicia needed a way to get a suffixed number for each page.
2    
3     >>> contents = open(r"\\ercdis12\Admin\Share\Felicia\newnewprivbegdocendoc.TXT").readlines()
4     >>> prekey = ""
5     >>> outputFile = open(r"c:\test_dir\Felicia.txt",'w')
6     >>> for line in contents:
7     ... line = line.replace("\n","")
8     ... key, begNo, endNo = line.split(",")
9     ... ranges = FixBatesRange_func.EnumerateBates(begNo,endNo)
10     ... if prekey == key:
11     ... pass
12     ... else:
13     ... count = 1
14     ... for i in ranges:
15     ... outputFile.write(i + "," + key + "." + str("%0*d"% (3,count)) + "\n")
16     ... count = count +1
17     ... prekey = key
18     ...
19     >>> outputFile.close()
20    
21    
22     And then she asked me to do a different one where they had 0008598_405663,BANERJEESEL0000001,BANERJEESEL0000120
23     and she needed a txt file with page by page matrix.
24    
25     >>> contents = open(r"C:\Test_dir\Felicia\stratiid-begbates-endbates.TXT").readlines()
26     >>> outputFile = open(r"C:\Test_dir\Felicia\20090520_Felicia.txt",'w')
27     >>> contents = contents[1:]
28     >>> len(contents)
29     479074
30     >>> for line in contents:
31     ... line = line.replace("\n","")
32     ... key, begNo, endNo = line.split(",")
33     ... ranges = FixBatesRange_func.EnumerateBates(begNo,endNo)
34     ... keyPrefix,keyInt = key.split("_")
35     ... keyInt = int(keyInt)
36     ... for i in ranges:
37     ... outputFile.write(keyPrefix + "_" + str(keyInt) + "," + i + "\n")
38     ... keyInt = keyInt + 1
39     ...
40     >>> outputFile.close()
41    
42     And then she asked me to do the same as the matrix one above but with a very strange BegImage, EndImage line, which
43     looked like this:
44     BEGIMAGE,ENDIMAGE,BEGBATES,ENDBATES
45     0008598_405663.0001,0008598_405663.0120,BANERJEESEL0000001,BANERJEESEL0000120
46    
47     >>> contents = open(r"C:\Test_dir\Felicia\20090612\allstrat xfs.TXT").readlines()
48     >>> outputFile = open(r"C:\Test_dir\Felicia\20090612_Allstrat.txt",'w')
49     >>> errorFile = open(r"C:\Test_dir\Felicia\20090612_Allstrat.err",'w')
50     >>> contents = contents[1:]
51     >>> len(contents)
52     478025
53     >>> for line in contents:
54     ... line = line.replace("\n","")
55     ... begImage,endImage, begNo, endNo = line.split(",")
56     ... imagePrefix,begImage = begImage.split('.')
57     ... nul,endImage = endImage.split('.')
58     ... imageRanges = FixBatesRange_func.EnumerateBates(begImage,endImage)
59     ... batesRanges = FixBatesRange_func.EnumerateBates(begNo,endNo)
60     ... if len(imageRanges) == len(batesRanges):
61     ... zippedRanges = zip(imageRanges,batesRanges)
62     ... for i in zippedRanges:
63     ... outputFile.write(imagePrefix + "." + str(i[0]) + "," + i[1] + "\n")
64     ... else:
65     ... errorFile.write(line + " Does not Match! \n")
66     ...
67     >>> outputFile.close()
68     >>> errorFile.close()
69    
70    
71     This was an easy one but it my prove useful to find these overlaps in the future. F needed to save all the documents
72     that had a number that was already used. like:
73    
74     doc001, doc005
75     doc005, doc007
76    
77     it was extra easy becuase the prefix was separated by a space.
78    
79     >>> outputFile = open(r"C:\Test_dir\Felicia\20090612_NEC.txt",'w')
80     >>> for line in contents:
81     ... line = line.replace("\n","")
82     ... begNo,endNo = line.split("|")
83     ... begInt = int(begNo.split(" ")[1])
84     ... endInt = int(endNo.split(" ")[1])
85     ... if begInt <= preline:
86     ... outputFile.write(begNo + "," + endNo + "\n")
87     ... preline = endInt
88     ...
89     >>> outputFile.close()