Skip to content

Commit

Permalink
Updated README, added new method to Bib class
Browse files Browse the repository at this point in the history
  • Loading branch information
charlottekostelic committed Jan 5, 2024
1 parent 1d8cb7e commit 4d983c4
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,20 @@ bib.remove_unsupported_subjects()
Python 3.7 and up.

## Version
> 0.8.1
> 0.9.0
## Changelog
### [0.9.0] - 2024-01-05
#### Changed
+ updated to pymarc 5.0
+ updated dev dependencies:
+ black (22.12.0)
+ pytest (7.4.4)

#### Added
+ `flat_dict()` method in `Bib` class that returns a dict without fields in a list


### [0.8.1] - 2022-08-16
#### Fixed
+ version bump propagated to all places
Expand Down Expand Up @@ -101,6 +112,7 @@ Python 3.7 and up.
#### Added
+ a method for retrieving branch call number as `pymarc.Field`

[0.9.0]: https://github.com/BookOps-CAT/bookops-marc/compare/0.8.1...0.9.0
[0.8.1]: https://github.com/BookOps-CAT/bookops-marc/compare/0.8.0...0.8.1
[0.8.0]: https://github.com/BookOps-CAT/bookops-marc/compare/0.7.0...0.8.0
[0.7.0]: https://github.com/BookOps-CAT/bookops-marc/compare/v0.6.0...0.7.0
Expand Down
2 changes: 1 addition & 1 deletion bookops_marc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.8.1"
__version__ = "0.9.0"

from .bib import Bib
from .reader import SierraBibReader
22 changes: 20 additions & 2 deletions bookops_marc/bib.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
Module replaces pymarc's Record module. Inherits all Record class functinality and
adds some syntactic sugar.
"""
from collections import namedtuple
from datetime import datetime, date
from typing import List, Optional
from typing import List, Optional, Dict

from pymarc import Record, Field
from pymarc.constants import LEADER_LEN
Expand Down Expand Up @@ -550,6 +549,25 @@ def upc_number(self) -> Optional[str]:
pass
return None

def flat_dict(self) -> Dict[str, str]:
"""
Turn a Bib into a dict with all fields in key,value pairs
Avoids the {"leader": value, "fields": []} structure of as_dict() method
"""
record: Dict = {"leader": str(self.leader)}

for field in self:
if field.tag < "010" and field.tag.isdigit():
record[field.tag] = field.data
else:
data = {
"ind1": field.indicator1,
"ind2": field.indicator2,
"subfields": [{s.code: s.value} for s in field.subfields],
}
record[field.tag] = data
return record


def pymarc_record_to_local_bib(record: Record, library: str) -> Bib:
"""
Expand Down
23 changes: 23 additions & 0 deletions tests/test_bib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,3 +1003,26 @@ def test_instating_from_pymarc_record(stub_pymarc_record, arg):

# bib methods
assert str(bib.main_entry()) == "=100 1\\$aAdams, John,$eauthor."


def test_flat_dict(stub_bib):
flattened = stub_bib.flat_dict()
assert flattened == {
"leader": "02866pam 2200517 i 4500",
"008": "190306s2017 ht a j 000 1 hat d",
"100": {
"ind1": "1",
"ind2": " ",
"subfields": [{"a": "Adams, John,"}, {"e": "author."}],
},
"245": {
"ind1": "1",
"ind2": "4",
"subfields": [{"a": "The foo /"}, {"c": "by John Adams."}],
},
"264": {
"ind1": " ",
"ind2": "1",
"subfields": [{"a": "Bar :"}, {"b": "New York,"}, {"c": "2021"}],
},
}
2 changes: 1 addition & 1 deletion tests/test_bookops_marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def test_version():
assert __version__ == "0.8.1"
assert __version__ == "0.9.0"


def test_Bib_top_import():
Expand Down

0 comments on commit 4d983c4

Please sign in to comment.