Skip to content

Commit 57f2639

Browse files
author
Gerit Wagner
committed
crossref: extract email setting
1 parent 217f526 commit 57f2639

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

colrev/packages/crossref/src/crossref_api.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import requests_cache
1717
from rapidfuzz import fuzz
1818

19-
import colrev.env.environment_manager
2019
import colrev.exceptions as colrev_exceptions
2120
import colrev.record.record_prep
2221
import colrev.utils
@@ -329,15 +328,21 @@ def __init__(
329328
self,
330329
*,
331330
url: str,
331+
email="my@email.edu",
332332
rerun: bool = False,
333333
cache: typing.Optional[bool] = None,
334334
):
335335
assert url.startswith(self._api_url)
336336
self.url = url
337337

338-
_, self.email = (
339-
colrev.env.environment_manager.EnvironmentManager.get_name_mail_from_git()
340-
)
338+
self.email = email
339+
if email == "my@email.edu":
340+
# warn
341+
print(
342+
"Warning: Using default email for Crossref API. "
343+
"Please set a valid email to comply with Crossref's polite usage policy."
344+
)
345+
341346
self.rerun = rerun
342347
# default: disable cache in CI; but allow explicit override
343348
if cache is None:
@@ -619,4 +624,4 @@ def query_doi(*, doi: str) -> colrev.record.record_prep.PrepRecord:
619624
except (requests.exceptions.RequestException, StopIteration) as exc:
620625
raise colrev_exceptions.RecordNotFoundInPrepSourceException(
621626
msg="Record not found in crossref (based on doi)"
622-
) from exc
627+
) from exc

colrev/packages/crossref/src/crossref_search_source.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import inquirer
1313
from pydantic import Field
14-
14+
import colrev.env.environment_manager
1515
import colrev.env.language_service
1616
import colrev.exceptions as colrev_exceptions
1717
import colrev.ops.search_api_feed
@@ -75,7 +75,10 @@ def __init__(
7575
else:
7676
url = self.search_source.search_parameters["url"]
7777

78-
self.api = crossref_api.CrossrefAPI(url=url)
78+
_, email = (
79+
colrev.env.environment_manager.EnvironmentManager.get_name_mail_from_git()
80+
)
81+
self.api = crossref_api.CrossrefAPI(url=url, email=email)
7982

8083
def _validate_source(self) -> None:
8184
# validate version and migrate if needed

0 commit comments

Comments
 (0)