pyalex 0.17__py3-none-any.whl → 0.18__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyalex/_version.py +2 -2
- pyalex/api.py +25 -11
- {pyalex-0.17.dist-info → pyalex-0.18.dist-info}/METADATA +1 -1
- pyalex-0.18.dist-info/RECORD +8 -0
- pyalex-0.17.dist-info/RECORD +0 -8
- {pyalex-0.17.dist-info → pyalex-0.18.dist-info}/LICENSE +0 -0
- {pyalex-0.17.dist-info → pyalex-0.18.dist-info}/WHEEL +0 -0
- {pyalex-0.17.dist-info → pyalex-0.18.dist-info}/top_level.txt +0 -0
pyalex/_version.py
CHANGED
pyalex/api.py
CHANGED
|
@@ -338,12 +338,12 @@ class Paginator:
|
|
|
338
338
|
self.value = value
|
|
339
339
|
self.per_page = per_page
|
|
340
340
|
self.n_max = n_max
|
|
341
|
+
self.n = 0
|
|
341
342
|
|
|
342
343
|
self._next_value = value
|
|
344
|
+
self._session = _get_requests_session()
|
|
343
345
|
|
|
344
346
|
def __iter__(self):
|
|
345
|
-
self.n = 0
|
|
346
|
-
|
|
347
347
|
return self
|
|
348
348
|
|
|
349
349
|
def _is_max(self):
|
|
@@ -356,13 +356,22 @@ class Paginator:
|
|
|
356
356
|
raise StopIteration
|
|
357
357
|
|
|
358
358
|
if self.method == "cursor":
|
|
359
|
-
|
|
359
|
+
self.endpoint_class._add_params("cursor", self._next_value)
|
|
360
360
|
elif self.method == "page":
|
|
361
|
-
|
|
361
|
+
self.endpoint_class._add_params("page", self._next_value)
|
|
362
362
|
else:
|
|
363
|
-
raise ValueError()
|
|
363
|
+
raise ValueError("Method should be 'cursor' or 'page'")
|
|
364
364
|
|
|
365
|
-
|
|
365
|
+
if self.per_page is not None and (
|
|
366
|
+
not isinstance(self.per_page, int)
|
|
367
|
+
or (self.per_page < 1 or self.per_page > 200)
|
|
368
|
+
):
|
|
369
|
+
raise ValueError("per_page should be a integer between 1 and 200")
|
|
370
|
+
|
|
371
|
+
if self.per_page is not None:
|
|
372
|
+
self.endpoint_class._add_params("per-page", self.per_page)
|
|
373
|
+
|
|
374
|
+
r = self.endpoint_class._get_from_url(self.endpoint_class.url, self._session)
|
|
366
375
|
|
|
367
376
|
if self.method == "cursor":
|
|
368
377
|
self._next_value = r.meta["next_cursor"]
|
|
@@ -499,8 +508,11 @@ class BaseOpenAlex:
|
|
|
499
508
|
"""
|
|
500
509
|
return self.get(per_page=1).meta["count"]
|
|
501
510
|
|
|
502
|
-
def _get_from_url(self, url):
|
|
503
|
-
|
|
511
|
+
def _get_from_url(self, url, session=None):
|
|
512
|
+
if session is None:
|
|
513
|
+
session = _get_requests_session()
|
|
514
|
+
|
|
515
|
+
res = session.get(url, auth=OpenAlexAuth(config))
|
|
504
516
|
|
|
505
517
|
if res.status_code == 403:
|
|
506
518
|
if (
|
|
@@ -526,8 +538,10 @@ class BaseOpenAlex:
|
|
|
526
538
|
raise ValueError("Unknown response format")
|
|
527
539
|
|
|
528
540
|
def get(self, return_meta=False, page=None, per_page=None, cursor=None):
|
|
529
|
-
if per_page is not None and (
|
|
530
|
-
|
|
541
|
+
if per_page is not None and (
|
|
542
|
+
not isinstance(per_page, int) or (per_page < 1 or per_page > 200)
|
|
543
|
+
):
|
|
544
|
+
raise ValueError("per_page should be an integer between 1 and 200")
|
|
531
545
|
|
|
532
546
|
if not isinstance(self.params, (str, list)):
|
|
533
547
|
self._add_params("per-page", per_page)
|
|
@@ -568,7 +582,7 @@ class BaseOpenAlex:
|
|
|
568
582
|
Paginator object.
|
|
569
583
|
"""
|
|
570
584
|
if method == "cursor":
|
|
571
|
-
if self.params.get("sample"):
|
|
585
|
+
if isinstance(self.params, dict) and self.params.get("sample"):
|
|
572
586
|
raise ValueError("method should be 'page' when using sample")
|
|
573
587
|
value = cursor
|
|
574
588
|
elif method == "page":
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
pyalex/__init__.py,sha256=upMXti6aJF6lz8J4EbdnQa13GhJzFGre7fnS_tj8NOw,1539
|
|
2
|
+
pyalex/_version.py,sha256=nGXfO1OzooW799_WlgmJZ-ipD8H1pUPrej1lNW4Um9M,508
|
|
3
|
+
pyalex/api.py,sha256=R5hDwrSlzmc3yia85DRF27DWJWpSw4b7DPqnUU_hGmw,27408
|
|
4
|
+
pyalex-0.18.dist-info/LICENSE,sha256=Mhf5MImRYP06a1EPVJCpkpTstOOEfGajN3T_Fz4izMg,1074
|
|
5
|
+
pyalex-0.18.dist-info/METADATA,sha256=GLWXRsSB6K9B5wAQpyHF1CCgJac9Sd6yvpcuZMHDWAg,14208
|
|
6
|
+
pyalex-0.18.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
|
7
|
+
pyalex-0.18.dist-info/top_level.txt,sha256=D0An8hWy9e0xPhTaT6K-yuJKVeVV3bYGxZ6Y-v2WXSU,7
|
|
8
|
+
pyalex-0.18.dist-info/RECORD,,
|
pyalex-0.17.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
pyalex/__init__.py,sha256=upMXti6aJF6lz8J4EbdnQa13GhJzFGre7fnS_tj8NOw,1539
|
|
2
|
-
pyalex/_version.py,sha256=t3d5dJC864lqQ-TUIs6gpWRp7YVH04dI08mpFt6wvR0,508
|
|
3
|
-
pyalex/api.py,sha256=05clKZlIcH7g7G5d7tELxrfUIyyzdPKwbRinZ1Pliy4,26783
|
|
4
|
-
pyalex-0.17.dist-info/LICENSE,sha256=Mhf5MImRYP06a1EPVJCpkpTstOOEfGajN3T_Fz4izMg,1074
|
|
5
|
-
pyalex-0.17.dist-info/METADATA,sha256=3K3i_n7uMyF91DfrwFI5t0X5jaYD8lD2HcySMNHcfbg,14208
|
|
6
|
-
pyalex-0.17.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
|
7
|
-
pyalex-0.17.dist-info/top_level.txt,sha256=D0An8hWy9e0xPhTaT6K-yuJKVeVV3bYGxZ6Y-v2WXSU,7
|
|
8
|
-
pyalex-0.17.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|