aboutsummaryrefslogtreecommitdiffstats
path: root/chocula/directories/entrez.py
blob: b30f04d51bb9866f2919cb4ec23f3291323f278e (plain)
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

from typing import Iterable, Optional
import csv

from chocula.util import clean_str
from chocula.common import DirectoryLoader
from chocula.database import DirectoryInfo


class EntrezLoader(DirectoryLoader):
    """
    CSV Columns:

    - JrId
    - JournalTitle
    - MedAbbr
    - "ISSN (Print)"
    - "ISSN (Online)"
    - IsoAbbr
    - NlmId
    """

    source_slug = "entrez"

    def open_file(self) -> Iterable:
        return csv.DictReader(open(self.config.entrez_simple.filepath))

    def parse_record(self, record) -> Optional[DirectoryInfo]:
        if not (record.get('ISSN (Online)') or record.get('ISSN (Print)')):
            return None
        return DirectoryInfo(
            directory_slug=self.source_slug,
            issne=record.get('ISSN (Online)'),
            issnp=record.get('ISSN (Print)'),
            custom_id=record.get('NlmId').strip() or None,
            name=clean_str(record.get('JournalTitle')),
            abbrev=clean_str(record['IsoAbbr']),
        )