-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathepisode_3.py
86 lines (73 loc) · 2.24 KB
/
episode_3.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from pymarc import MARCReader
my_marc_file = "NLNZ_example_marc.marc"
print ("Finding specific fields with PyMARC")
print ()
print ("\t ______Print a record______")
print ()
with open(my_marc_file, 'rb') as data:
reader = MARCReader(data)
for record in reader:
print (record)
break
print ()
print ("\t ______Print a field______")
print ()
with open(my_marc_file, 'rb') as data:
reader = MARCReader(data)
for record in reader:
print (record['245'])
print ()
print ("\t ______Print a key that doesn't exist______")
print ()
with open(my_marc_file, 'rb') as data:
reader = MARCReader(data)
for record in reader:
print (record['this_key_doesnt_exist'])
break
print()
print ("\t ______Accessing Subfields______")
print ()
with open(my_marc_file, 'rb') as data:
reader = MARCReader(data)
for record in reader:
print ("Subfield 'a':", record['245']['a'])
print ("Subfield 'b':", record['245']['b'])
print ("Subfield 'c':", record['245']['c'])
break
print()
print ("\t ______Print the same information in different ways______")
print ()
with open(my_marc_file, 'rb') as data:
reader = MARCReader(data)
for record in reader:
print (type(record))
print ()
print (record['245'])
print (type(record['245']))
print ()
print (record['245'].value())
print (type(record['245'].value()))
print ()
print (record['245']['a'])
print (type(record['245']['a']))
print ()
print (record.title())
print (type(record.title()))
break
# print ()
print ("\t ______Find a particular record by its unique ID_____")
print ()
with open(my_marc_file, 'rb') as data:
reader = MARCReader(data)
for record in reader:
if record['001'].value() == str(99628153502836):
print ("Success! found record with id 99628153502836")
print ()
print ("\t ______Find a particular record by its unique ID as a variable_____")
print ()
with open(my_marc_file, 'rb') as data:
reader = MARCReader(data)
search_id = 99628153502836
for record in reader:
if record['001'].value() == str(search_id):
print (f"Success! found record with id {search_id}")