From a52e5f39346e28bdb2eb58f17a298177659dbbfe Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 8 Oct 2020 17:36:07 -0700 Subject: database support for scholarsportal and cariniana preservation holdings --- chocula/common.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'chocula/common.py') diff --git a/chocula/common.py b/chocula/common.py index edd48a3..94c4c7f 100644 --- a/chocula/common.py +++ b/chocula/common.py @@ -148,6 +148,9 @@ class KbartLoader: else: new_spans = [[record.start_year, record.end_year]] record.year_spans = merge_spans(old_spans, new_spans) + elif record.year_spans: + old_spans = existing.year_spans or [] + record.year_spans = merge_spans(old_spans, record.year_spans) kbart_dict[record.issnl] = record counts["unique-issnl"] = len(kbart_dict) @@ -218,6 +221,54 @@ class OnixCsvLoader(KbartLoader): return record +class CarinianaCsvLoader(KbartLoader): + """ + Similar to the KBART loader class, but for custom CSV files instead of + KBART formated TSV. + + CSV columns: + - Region + - Knowledge Area + - Publisher + - Title + - ISSN + - eISSN + - Preserved Volumes + - Preserved Years + - In Progress Volumes + - In Progress Years + + TODO: volumes + """ + + def open_file(self) -> Iterable: + return csv.DictReader(open(self.file_path(), "r")) + + def parse_record(self, row: dict, issn_db: IssnDatabase) -> Optional[KbartRecord]: + + raw_issn = clean_issn(row["ISSN"]) + issne = clean_issn(row["ISSN"]) + issnl = issn_db.issn2issnl(raw_issn or issne or "") + # convert list of years to a set of year spans + years = [int(y.strip()) for y in row["Preserved Years"].split(";") if y] + year_spans = merge_spans([], [[y, y] for y in years]) + record = KbartRecord( + issnl=issnl, + issne=issne, + issnp=None, + embargo=None, + title=clean_str(row["Title"]), + publisher=clean_str(row["Publisher"]), + url=None, + start_year=None, + end_year=None, + start_volume=None, + end_volume=None, + year_spans=year_spans, + ) + return record + + class HathifilesLoader(KbartLoader): """ Similar to the KBART loader class, but for Hathifiles bulk format. -- cgit v1.2.3