Skip to content

Commit

Permalink
use imprints date from tag rather than publication_date
Browse files Browse the repository at this point in the history
  • Loading branch information
MJedr committed Jan 24, 2023
1 parent 78d239a commit 707b46a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
17 changes: 14 additions & 3 deletions hepcrawl/parsers/elsevier.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,12 @@ def parse(self):
self.builder.add_doi(**doi)
for keyword in self.keywords:
self.builder.add_keyword(keyword)
self.builder.add_imprint_date(
self.publication_date.dumps() if self.publication_date else None
)
if self.imprints_date:
self.builder.add_imprint_date(self.imprints_date)
elif self.publication_date:
self.builder.add_imprint_date(
self.publication_date.dumps()
)
for reference in self.references:
self.builder.add_reference(reference)

Expand Down Expand Up @@ -372,6 +375,14 @@ def page_end(self):
).extract_first()
return page_end

@property
def imprints_date(self):
imprints_date = self.root.xpath(
"string(./RDF/Description/availableOnlineInformation/availableOnline)"
).extract_first()
if imprints_date:
return PartialDate.parse(imprints_date).dumps()

@property
def publication_date(self):
publication_date = None
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
}

setup_requires = [
'autosemver~=0.2',
"autosemver~=0.0,>=0.5.2,<1.0.0",
]

extras_require['all'] = []
Expand Down
1 change: 1 addition & 0 deletions tests/unit/responses/elsevier/j.nima.2023.168018.xml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions tests/unit/test_parsers_elsevier.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,9 @@ def test_record_should_be_harvested(records):
def test_record_shouldnt_be_harvested():
parser = get_parser_by_file("record-that-shouldnt-be-harvested.xml")
assert not parser.should_record_be_harvested()


def test_imprints_date_should_be_taken_from_avaliable_online():
parser = get_parser_by_file("j.nima.2023.168018.xml")
result = parser.parse()
assert result['imprints'] == [{'date': '2023-01-02'}]

0 comments on commit 707b46a

Please sign in to comment.