-
Notifications
You must be signed in to change notification settings - Fork 1
/
extractCompleteNamesSubjectsFromCSV.py
45 lines (42 loc) · 1.68 KB
/
extractCompleteNamesSubjectsFromCSV.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import csv
filename = 'marcFields.csv'
f = csv.writer(open('personalNamesComplete.csv', 'w'))
f.writerow(['bibnum'] + ['value'])
f2 = csv.writer(open('corporateNamesComplete.csv', 'w'))
f2.writerow(['bibnum'] + ['value'])
f3 = csv.writer(open('miscNamesComplete.csv', 'w'))
f3.writerow(['bibnum'] + ['value'])
f4 = csv.writer(open('subjectsComplete.csv', 'w'))
f4.writerow(['bibnum'] + ['value'])
with open(filename) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
bibnum = row['bibnum']
# personal
if row['tag'] == '100':
f.writerow([bibnum] + [row['tag']] + [row['value']])
if row['tag'] == '600':
f.writerow([bibnum] + [row['tag']] + [row['value']])
if row['tag'] == '700':
f.writerow([bibnum] + [row['tag']] + [row['value']])
# corporate
if row['tag'] == '110':
f2.writerow([bibnum] + [row['tag']] + [row['value']])
if row['tag'] == '610':
f2.writerow([bibnum] + [row['tag']] + [row['value']])
if row['tag'] == '710':
f2.writerow([bibnum] + [row['tag']] + [row['value']])
# miscNames
if row['tag'].startswith('1') and \
row['tag'] != '100' and \
row['tag'] != '110':
f3.writerow([bibnum] + [row['tag']] + [row['value']])
if row['tag'].startswith('7') and \
row['tag'] != '700' and \
row['tag'] != '710':
f3.writerow([bibnum] + [row['tag']] + [row['value']])
# subjects
if row['tag'].startswith('6') and \
row['tag'] != '600' and \
row['tag'] != '610':
f4.writerow([bibnum] + [row['tag']] + [row['value']])