aboutsummaryrefslogtreecommitdiffstats
path: root/chocula/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'chocula/common.py')
-rw-r--r--chocula/common.py51
1 files changed, 51 insertions, 0 deletions
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.