Skip to content

Commit

Permalink
Merge pull request #75 from Coleridge-Initiative/el3220/Issue_72_Sema…
Browse files Browse the repository at this point in the history
…ntic_scholar

el3220/issue 72 semantic scholar
  • Loading branch information
ernestogimeno authored Aug 20, 2020
2 parents ab0f897 + f42a807 commit 25dc844
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions richcontext/scholapi/scholapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,16 @@ def publication_lookup (self, identifier):

t0 = time.time()
url = self._get_api_url(identifier)
meta = json.loads(requests.get(url).text)
response = requests.get(url)
if response.status_code == requests.codes.ok:
meta = json.loads(response.text)

if not meta or len(meta) < 1 or "error" in meta:
meta = None

elif "message" in meta:
message = meta["message"]
meta = None

timing = self._mark_elapsed_time(t0)
return _ScholInfraResponse_SemanticScholar(self, meta, timing, message)

Expand Down
7 changes: 7 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,13 @@ def test_semantic_publication_lookup (self):
response = source.publication_lookup(doi)
self.assertTrue(response.meta == None)

# another error case
doi = "10.1641/0006-3568(2005)055[0879:EITLSA]2.0.CO;2"

if source.has_credentials():
response = source.publication_lookup(doi)
self.assertTrue(response.meta == None)


######################################################################
## Misc. family of APIs
Expand Down

0 comments on commit 25dc844

Please sign in to comment.