Skip to content

Commit 7af4b81

Browse files
Tweaks to docs, add pagination example to "usage.md"
1 parent 4043f2d commit 7af4b81

2 files changed

Lines changed: 44 additions & 14 deletions

File tree

docs/caveats.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ and to reuse the structure in [`seasons`][simplejustwatchapi.justwatch.seasons].
3232

3333
Some fields in returned data is marked as optional (through `| None`). Since there is no
3434
documentation for the JustWatch GraphQL API I tried to mark as optional fields which I
35-
found to **actually** be optional, rather than mark everything. However, there is no
36-
guarantee what the API will return, so if you need maximum safety you might need to
37-
treat **all** fields as effectively optional (as in - they can be `None`).
35+
found to **actually** be optional, rather than mark everything.
36+
37+
However, there is no guarantee what the API will return, so if you need maximum safety
38+
you might need to treat **all** fields as effectively optional (as in - they can be
39+
`None`).
3840

3941

4042

@@ -78,7 +80,7 @@ The sufix must be uppercase:
7880
^[a-z]{2}(-[0-9A-Z]+)?$
7981
```
8082

81-
It looks similar to **IETF BCP 47** standard.
83+
It looks similar to **IETF BCP 47** standard, without `-` characters in the suffix.
8284

8385
!!! warning "Language code letter case"
8486
The provided language isn't modified at all by this library, so it must match the

docs/usage.md

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ All needed functions, data structures, raised exceptions are available through s
2727
module - `simplejustwatchapi`.
2828

2929
Examples of parsed responses are in the GitHub repository in
30-
[`examples/`](https://github.com/Electronic-Mango/simple-justwatch-python-api/tree/\
31-
main/examples).
30+
[`examples/`](https://github.com/Electronic-Mango/simple-justwatch-python-api/tree/main/examples).
3231

3332

3433
## Functions
@@ -70,15 +69,15 @@ for entry in results:
7069
print(entry.title, entry.offers)
7170
```
7271

72+
!!! note "Whitespaces in title"
73+
Value of the given title isn't stripped, so passing a string with multiple spaces
74+
will look them up. For more than 1 space it will probably return an empty list.
75+
7376
All arguments are optional.
7477

7578
First argument is just a string to look up. If empty, or not provided, you'll get a
7679
selection of popular titles, similar to [`popular`](#popular) function.
7780

78-
!!! note "Whitespaces in title"
79-
value of `title` isn't stripped, so passing a string with multiple spaces will look
80-
them up. For more than 1 space it will (probably) always return an empty list.
81-
8281
For very large searches (high `count` value) I recommend using default `best_only=True`
8382
to avoid issues with [operation complexity](caveats.md#operation-complexity).
8483
Alternatively you can `offset` for
@@ -143,6 +142,7 @@ This function can be used for all types of media - shows, movies, episodes, seas
143142
(the last two having their dedicated functions described below), for all types the
144143
result is a single [`MediaEntry`][simplejustwatchapi.tuples.MediaEntry]. Some fields
145144
are specific for one of the media types and will be `None` for others - for example:
145+
146146
- `total_episode_count` is only present for seasons
147147
- `season_number` is present for seasons and episodes
148148
- `episode_number` is present only for episodes
@@ -351,17 +351,17 @@ except JustWatchApiError as e:
351351
print(",".join(error_messages))
352352
```
353353

354-
And so on.
354+
These are just examples of internal API errors, which cause [`JustWatchApiError`]
355+
[simplejustwatchapi.exceptions.JustWatchApiError] exception.
355356

356357

357-
## Multi-function examples
358-
359-
Small collection of examples of how you can combine multiple functions together.
358+
## More complicated examples
360359

361360
### Get popular titles for only specific providers
362361

363362
You can combine [`providers`](#get-all-available-providers-for-a-country) and
364363
[`popular`](#popular-titles) functions:
364+
365365
```python
366366
from simplejustwatchapi import popular, providers
367367

@@ -385,6 +385,7 @@ filtered_popular = popular("US", providers=netflix_apple_only)
385385
You can combine [`search`](#search-for-a-title),
386386
[`seasons`](#details-for-all-seasons-of-a-tv-show) and
387387
[`episodes`](#details-for-all-episodes-of-a-tv-show) functions:
388+
388389
```python
389390
from simplejustwatchapi import episodes, search, seasons
390391

@@ -420,6 +421,7 @@ You can combine [`search`](#search-for-a-title),
420421
[`seasons`](#details-for-all-seasons-of-a-tv-show) and
421422
[`offers_for_countries`](#get-offers-for-multiple-countries-for-a-single-title)
422423
functions:
424+
423425
```python
424426
from simplejustwatchapi import offers_for_countries, search, seasons
425427

@@ -454,3 +456,29 @@ season_offers_per_country = {
454456
for country in countries
455457
}
456458
```
459+
460+
461+
### Pagination through `offset`
462+
463+
When trying to get as much data as possible with [`search`](#search-for-a-title) or
464+
[`popular`](#popular-titles) functions and avoid issues with
465+
[operation complexity](caveats.md#operation-complexity) you can use `offset` parameter
466+
to set up a [basic pagination](caveats.md#getting-more-results-and-pagination):
467+
468+
```python
469+
from simplejustwatchapi import popular
470+
471+
i = 0
472+
page = 99
473+
all_results = []
474+
while results := popular(count=page, offset=i):
475+
i += page
476+
all_results.extend(results)
477+
# len(all_results) == 1980
478+
```
479+
480+
!!! note "Maximum number of responses"
481+
There is a limit of number of entries you can get from the JustWatch API using this
482+
method of **1999**. Check
483+
[Maximum number of entries](caveats.md#maximum-number-of-entries) page for more
484+
details.

0 commit comments

Comments
 (0)