Skip to content

Commit

Permalink
Indented over sessions to make more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbraza committed Apr 1, 2024
1 parent 2f727eb commit cdfd613
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions paperscraper/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,34 +523,32 @@ async def google2s2(
)
return None
response = await response.json() # noqa: PLW2901
if ( # noqa: SIM102
"data" not in response and year is not None
):
if response["total"] == 0:
logger.info(
f"{title} | {year} not found. Now trying without year"
if (
"data" not in response
and year is not None
and response["total"] == 0
):
logger.info(
f"{title} | {year} not found. Now trying without year"
)
del local_p["year"]
async with ss_sub_session.get(
url=endpoint, params=local_p
) as resp:
if not resp.ok:
logger.warning(
"Error correlating papers from google"
" to semantic scholar (no year):"
f" status {resp.status}, reason {resp.reason},"
f" text {await resp.text()!r}."
)
del local_p["year"]
async with ss_sub_session.get(
url=endpoint, params=local_p
) as resp:
if not resp.ok:
logger.warning(
"Error correlating papers from google"
" to semantic scholar (no year):"
f" status {resp.status},"
f" reason {resp.reason},"
f" text {await resp.text()!r}."
)
response = await resp.json() # noqa: PLW2901
if "data" in response:
if pdf_link is not None:
# google scholar url takes precedence
response["data"][0]["openAccessPdf"] = {
"url": pdf_link
}
return response["data"][0]
return None
response = await resp.json()
if "data" in response:
if pdf_link is not None:
# google scholar url takes precedence
response["data"][0]["openAccessPdf"] = {"url": pdf_link}
return response["data"][0]
return None

responses = await asyncio.gather(
*(
Expand Down

0 comments on commit cdfd613

Please sign in to comment.