From aecfce44acb2b4e4c8b8509c5a00f32f089bd2a6 Mon Sep 17 00:00:00 2001 From: Renaud Boyer Date: Mon, 9 Dec 2019 16:23:00 +0100 Subject: [PATCH 1/4] ISSN title and number --- pymarc/record.py | 26 +++++++++++++++++++++++++- test/record.py | 23 +++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/pymarc/record.py b/pymarc/record.py index 63be139..745e021 100644 --- a/pymarc/record.py +++ b/pymarc/record.py @@ -419,7 +419,7 @@ def as_json(self, **kwargs): def title(self): """ - Returns the title of the record (245 $a an $b). + Returns the title of the record (245 $a and $b). """ try: title = self['245']['a'] @@ -432,6 +432,21 @@ def title(self): pass return title + def issn_title(self): + """ + Returns the key title of the record (222 $a and $b). + """ + try: + title = self['222']['a'] + except TypeError: + title = None + if title: + try: + title += " " + self['222']['b'] + except TypeError: + pass + return title + def isbn(self): """ Returns the first ISBN in the record or None if one is not @@ -451,6 +466,15 @@ def isbn(self): pass return None + def issn(self): + """ + Returns the ISSN number [022]['a'] in the record or None + """ + try: + return self['022']['a'] + except TypeError: + return None + def sudoc(self): """ Returns a Superintendent of Documents (SuDoc) classification number diff --git a/test/record.py b/test/record.py index 3435a9d..6ff146c 100644 --- a/test/record.py +++ b/test/record.py @@ -111,6 +111,23 @@ def test_title(self): subfields=['a', "Farghin"])) self.assertEqual(record.title(), "Farghin") + def test_issn_title(self): + record = Record() + self.assertEqual(record.issn_title(), None) + record.add_field(Field('222', ["", ""], + subfields=['a', 'Foo :', 'b', 'bar'])) + self.assertEqual(record.issn_title(), 'Foo : bar') + + record = Record() + record.add_field(Field('222', ["", ""], + subfields=['a', "Farghin"])) + self.assertEqual(record.issn_title(), "Farghin") + + record = Record() + record.add_field(Field('222', ["", ""], + subfields=['b', "bar"])) + self.assertEqual(record.issn_title(), None) + def test_isbn(self): record = Record() self.assertEqual(record.isbn(), None) @@ -133,6 +150,12 @@ def test_isbn(self): record.add_field(Field('020', [' ', ' '], subfields=['a', '006073132X'])) self.assertEqual(record.isbn(), '006073132X') + def test_issn(self): + record = Record() + self.assertEqual(record.issn(), None) + record.add_field(Field(tag="022", indicators=["0", ""], subfields=["a", "0395-2037"])) + self.assertEqual(record.isbn(), '0395-2037') + def test_multiple_isbn(self): with open('test/multi_isbn.dat', 'rb') as fh: reader = MARCReader(fh) From fa934edf77681e2c46c036e2d71d736e4ff44ef2 Mon Sep 17 00:00:00 2001 From: Renaud Boyer Date: Mon, 9 Dec 2019 17:12:15 +0100 Subject: [PATCH 2/4] fix indentation --- test/record.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/record.py b/test/record.py index 6ff146c..349fc8f 100644 --- a/test/record.py +++ b/test/record.py @@ -150,7 +150,7 @@ def test_isbn(self): record.add_field(Field('020', [' ', ' '], subfields=['a', '006073132X'])) self.assertEqual(record.isbn(), '006073132X') - def test_issn(self): + def test_issn(self): record = Record() self.assertEqual(record.issn(), None) record.add_field(Field(tag="022", indicators=["0", ""], subfields=["a", "0395-2037"])) From 3c56f4d86a19a765518c02caa77020b510dfe1b5 Mon Sep 17 00:00:00 2001 From: Renaud Boyer Date: Mon, 9 Dec 2019 17:15:12 +0100 Subject: [PATCH 3/4] Mention issn methods in the readme --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 98883b2..83cffbf 100644 --- a/README.md +++ b/README.md @@ -83,12 +83,12 @@ ANSI Common Lisp / A `pymarc.Record` object has a few handy methods like `title` for getting at bits of a bibliographic record, others include: `author`, `isbn`, `subjects`, -`location`, `notes`, `physicaldescription`, `publisher`, `pubyear`. But -really, to work with MARC data you need to understand the numeric field tags -and subfield codes that are used to designate various bits of information. There -is a lot more hiding in a MARC record than these methods provide access to. -For example the `title` method extracts the information from the `245` field, -subfields `a` and `b`. You can access `245a` like so: +`location`, `notes`, `physicaldescription`, `publisher`, `pubyear`, `issn`, +`issn_title`. But really, to work with MARC data you need to understand the +numeric field tags and subfield codes that are used to designate various bits +of information. There is a lot more hiding in a MARC record than these methods +provide access to. For example the `title` method extracts the information from + the `245` field, subfields `a` and `b`. You can access `245a` like so: ```python print(record['245']['a']) From f6a8b1593a9ebf92830e23d42197ec48f340b497 Mon Sep 17 00:00:00 2001 From: Renaud Boyer Date: Mon, 9 Dec 2019 18:04:45 +0100 Subject: [PATCH 4/4] Fix typo --- test/record.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/record.py b/test/record.py index 349fc8f..9c814dd 100644 --- a/test/record.py +++ b/test/record.py @@ -154,7 +154,7 @@ def test_issn(self): record = Record() self.assertEqual(record.issn(), None) record.add_field(Field(tag="022", indicators=["0", ""], subfields=["a", "0395-2037"])) - self.assertEqual(record.isbn(), '0395-2037') + self.assertEqual(record.issn(), '0395-2037') def test_multiple_isbn(self): with open('test/multi_isbn.dat', 'rb') as fh: