Skip to content

Commit

Permalink
refactor: extract method to get not found IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnsilva committed Jan 14, 2024
1 parent 3eb5516 commit cc0d77e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions semanticscholar/AsyncSemanticScholar.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ async def get_papers(
url, parameters, self.auth_header, payload)
papers = [Paper(item) for item in data if item is not None]

not_found_ids = self._get_not_found_ids(paper_ids, papers)

if not_found_ids:
warnings.warn(f"IDs not found: {not_found_ids}")

return papers if not return_not_found else (papers, not_found_ids)

def _get_not_found_ids(self, paper_ids, papers):

prefix_mapping = {
'ARXIV': 'ArXiv',
'MAG': 'MAG',
Expand All @@ -193,10 +202,7 @@ async def get_papers(

not_found_ids = [id for id in paper_ids if id.lower() not in found_ids]

if not_found_ids:
warnings.warn(f"IDs not found: {not_found_ids}")

return papers if not return_not_found else (papers, not_found_ids)
return not_found_ids

async def get_paper_authors(
self,
Expand Down

0 comments on commit cc0d77e

Please sign in to comment.