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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
import sys
from typing import Iterable, Optional, Dict, Any
import csv
import ftfy
from chocula.util import clean_str, parse_country
from chocula.common import DirectoryLoader
from chocula.database import DirectoryInfo
class SherpaRomeoLoader(DirectoryLoader):
"""
CSV Columns:
#RoMEO Record ID,Publisher,Policy Heading,Country,RoMEO colour,Published Permission,Published Restrictions,Published Max embargo,Accepted Prmission,Accepted Restrictions,Accepted Max embargo,Submitted Permission,Submitted Restrictions,Submitted Max embargo,Open Access Publishing,Record Status,Updated
#Journal Title,ISSN,ESSN,URL,RoMEO Record ID,Updated
"""
source_slug = "sherpa_romeo"
sherpa_policies: Dict[str, Any] = dict()
def open_file(self) -> Iterable:
# first load policies
print("##### Loading SHERPA/ROMEO policies...", file=sys.stderr)
fixed_policy_file = ftfy.fix_file(open(self.config.SHERPA_ROMEO_POLICY_FILE, 'rb'))
policy_reader = csv.DictReader(fixed_policy_file)
for row in policy_reader:
self.sherpa_policies[row['RoMEO Record ID']] = row
# then open regular file
raw_file = open(self.config.SHERPA_ROMEO_JOURNAL_FILE, 'rb').read().decode(errors='replace')
fixed_file = ftfy.fix_text(raw_file)
return csv.DictReader(fixed_file.split('\n'))
def parse_record(self, row) -> Optional[DirectoryInfo]:
# super mangled :(
row.update(self.sherpa_policies[row['RoMEO Record ID']])
info = DirectoryInfo(
directory_slug=self.source_slug,
issnp=row['ISSN'],
issne=row['ESSN'],
name=clean_str(row['Journal Title']),
publisher=clean_str(row['Publisher']),
country=parse_country(row['Country']),
custom_id=row['RoMEO Record ID'],
)
if row['RoMEO colour']:
info.extra['sherpa_romeo'] = dict(color=row['RoMEO colour'])
return info
|