Last change
on this file since 34299 was 34227, checked in by kjdon, 4 years ago |
the processing files to help you generate metadata.xml files for the programmes
|
File size:
1.6 KB
|
Line | |
---|
1 | import sys
|
---|
2 | import os
|
---|
3 |
|
---|
4 | #open the file and return an array of the lines in the file
|
---|
5 | def openFile(filename):
|
---|
6 |
|
---|
7 | programme = open(filename)
|
---|
8 | lines = programme.readlines()
|
---|
9 | programme.close()
|
---|
10 |
|
---|
11 | new_lines = []
|
---|
12 |
|
---|
13 | for line in lines:
|
---|
14 | line = line.strip()
|
---|
15 | if line:
|
---|
16 | new_lines.append(line)
|
---|
17 |
|
---|
18 | return new_lines
|
---|
19 |
|
---|
20 | def checkForSpecial(name):
|
---|
21 |
|
---|
22 | name_parts = name.split()
|
---|
23 | if len(name_parts) > 2:
|
---|
24 | if (name_parts[0] == "conductor") | (name_parts[0] == "soloist"):
|
---|
25 | i = 1
|
---|
26 | name = ""
|
---|
27 | while i < len(name_parts):
|
---|
28 | name += name_parts[i] + " "
|
---|
29 | i +=1
|
---|
30 |
|
---|
31 | return name.strip()
|
---|
32 |
|
---|
33 | def removeDuplicates(lines):
|
---|
34 |
|
---|
35 | checked = []
|
---|
36 | for name in lines:
|
---|
37 | if name not in checked:
|
---|
38 | checked.append(name)
|
---|
39 |
|
---|
40 | return checked
|
---|
41 |
|
---|
42 | #write names out to file, takes orig_file as name so that new file can be created based on original file name
|
---|
43 | #takes doc array of names to write to file
|
---|
44 | def writeToFile(lines):
|
---|
45 |
|
---|
46 | new_file_name = "master_name_list.txt"
|
---|
47 |
|
---|
48 | if os.path.exists(new_file_name):
|
---|
49 | new_file = file(new_file_name, "r+")
|
---|
50 | else:
|
---|
51 | new_file = file(new_file_name, "w+")
|
---|
52 |
|
---|
53 | for name in lines:
|
---|
54 | new_file.write(name + "\n")
|
---|
55 |
|
---|
56 | print "Finished writing names to " + new_file_name
|
---|
57 |
|
---|
58 | #main method which calls methods in order of execution required
|
---|
59 | def main():
|
---|
60 |
|
---|
61 | new_lines = []
|
---|
62 | i = 1
|
---|
63 | while i < len(sys.argv):
|
---|
64 | lines = openFile(sys.argv[i])
|
---|
65 | extras = openFile("master_name_list.txt")
|
---|
66 |
|
---|
67 | for extra in extras:
|
---|
68 | new_lines.append(extra)
|
---|
69 |
|
---|
70 | for name in lines:
|
---|
71 | new_name = checkForSpecial(name)
|
---|
72 | new_lines.append(new_name)
|
---|
73 |
|
---|
74 | new_lines.sort()
|
---|
75 |
|
---|
76 | new_lines = removeDuplicates(new_lines)
|
---|
77 |
|
---|
78 | writeToFile(new_lines)
|
---|
79 | i += 1
|
---|
80 |
|
---|
81 | main()
|
---|
Note:
See
TracBrowser
for help on using the repository browser.