Skip to content

Commit

Permalink
Small refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
J535D165 committed Oct 23, 2023
1 parent 0d51a9f commit 4942606
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions pyalex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,7 @@ def _params_merge(params, add_params):
params[k] = add_params[k]


def invert_abstract(inv_index):
if inv_index is not None:
l_inv = [(w, p) for w, pos in inv_index.items() for p in pos]
return " ".join(map(lambda x: x[0], sorted(l_inv, key=lambda x: x[1])))


def get_requests_session():
def _get_requests_session():
# create an Requests Session with automatic retry:
requests_session = requests.Session()
retries = Retry(
Expand All @@ -98,6 +92,12 @@ def get_requests_session():
return requests_session


def invert_abstract(inv_index):
if inv_index is not None:
l_inv = [(w, p) for w, pos in inv_index.items() for p in pos]
return " ".join(map(lambda x: x[0], sorted(l_inv, key=lambda x: x[1])))


class QueryError(ValueError):
pass

Expand All @@ -118,7 +118,7 @@ def __getitem__(self, key):
def ngrams(self, return_meta=False):
openalex_id = self["id"].split("/")[-1]

res = get_requests_session().get(
res = _get_requests_session().get(
f"{config.openalex_url}/works/{openalex_id}/ngrams",
headers={"User-Agent": "pyalex/" + __version__, "email": config.email},
)
Expand Down Expand Up @@ -156,10 +156,7 @@ class Funder(OpenAlexEntity):
pass


# deprecated


def Venue(*args, **kwargs):
def Venue(*args, **kwargs): # deprecated
# warn about deprecation
warnings.warn(
"Venue is deprecated. Use Sources instead.",
Expand Down Expand Up @@ -287,7 +284,7 @@ def count(self):

def _get_from_url(self, url, return_meta=False):
params = {"api_key": config.api_key} if config.api_key else {}
res = requests.get(
res = _get_requests_session().get(
self.url,
headers={"User-Agent": "pyalex/" + __version__, "email": config.email},
params=params,
Expand Down Expand Up @@ -408,10 +405,7 @@ class Funders(BaseOpenAlex):
resource_class = Funder


# deprecated


def Venues(*args, **kwargs):
def Venues(*args, **kwargs): # deprecated
# warn about deprecation
warnings.warn(
"Venues is deprecated. Use Sources instead.",
Expand Down

0 comments on commit 4942606

Please sign in to comment.