From 2b6160a44ce468ef2195dab8f8d30f396e627d13 Mon Sep 17 00:00:00 2001 From: Erik Lopez Date: Wed, 8 Jul 2020 11:21:21 -0400 Subject: [PATCH] including fields only if defined --- richcontext/scholapi/scholapi.py | 20 ++++++++++++++++---- test.py | 6 ++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/richcontext/scholapi/scholapi.py b/richcontext/scholapi/scholapi.py index 2a3f5e8..ac58e11 100755 --- a/richcontext/scholapi/scholapi.py +++ b/richcontext/scholapi/scholapi.py @@ -315,10 +315,22 @@ def title_search (self, title): result_title = self._get_xml_node_value(result, "title") if self.title_match(title, result_title): - meta["doi"] = self._get_xml_node_value(result, "pid", {"classname": "doi"}) - meta["title"] = self._get_xml_node_value(result, "title") - meta["url"] = self._get_xml_node_value(result, "url") - meta["authors"] = [a.text for a in result.find_all("creator")] + val = self._get_xml_node_value(result, "pid", {"classname": "doi"}) + if val: + meta["doi"] = val + + val = self._get_xml_node_value(result, "title") + if val: + meta["title"] = val + + val = self._get_xml_node_value(result, "url") + if val: + meta["url"] = val + + val = [a.text for a in result.find_all("creator")] + if val: + meta["authors"] = val + meta["open"] = len(result.find_all("bestaccessright", {"classid": "OPEN"})) > 0 timing = self._mark_elapsed_time(t0) diff --git a/test.py b/test.py index 555a664..c8da2d7 100755 --- a/test.py +++ b/test.py @@ -247,6 +247,12 @@ def test_openaire_title_search (self): self.assertTrue(response.authors() == authors) self.assertTrue(response.meta["open"]) + title = "Quantitative easing, portfolio rebalancing and credit growth: Micro evidence from Germany" + if source.has_credentials(): + response = source.title_search(title) + source.report_perf(response.timing) + self.assertTrue("doi" not in response.meta) + self.assertTrue(response.title() == title) def test_openaire_fulltext_search (self): schol = rc_scholapi.ScholInfraAPI(config_file="rc.cfg")