Skip to content

Commit 22ce926

Browse files
Add more advanced examples to "usage.md" docs page
Examples of how you can combine output from multiple functions.
1 parent a7022a5 commit 22ce926

1 file changed

Lines changed: 100 additions & 1 deletion

File tree

docs/usage.md

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,103 @@ except JustWatchApiError as e:
354354
And so on.
355355

356356

357-
## Advanced examples
357+
## Multi-function examples
358+
359+
Small collection of examples of how you can combine multiple functions together.
360+
361+
### Get popular titles for only specific providers
362+
363+
You can combine [`providers`](#get-all-available-providers-for-a-country) and
364+
[`popular`](#popular-titles) functions:
365+
```python
366+
from simplejustwatchapi import popular, providers
367+
368+
# Get all providers in the US.
369+
all_providers = providers("US")
370+
371+
# Filter only required providers by name.
372+
netflix_apple_only = [
373+
provider.short_name # We only need the codes for filtering.
374+
for provider in all_providers
375+
if provider.name in ("Netflix", "Apple TV") # Get providers we need.
376+
]
377+
378+
# Use found codes for filtering.
379+
filtered_popular = popular("US", providers=netflix_apple_only)
380+
```
381+
382+
383+
### Get offers for each episode of a TV show based on title
384+
385+
You can combine [`search`](#search-for-a-title),
386+
[`seasons`](#details-for-all-seasons-of-a-tv-show) and
387+
[`episodes`](#details-for-all-episodes-of-a-tv-show) functions:
388+
```python
389+
from simplejustwatchapi import episodes, search, seasons
390+
391+
title = "True Detective"
392+
393+
# Search for a title.
394+
search_results = search(title)
395+
396+
# Look for a first match with the expected title.
397+
first_match = next(
398+
result
399+
for result in search_results
400+
if result.title == title and result.object_type == "SHOW"
401+
)
402+
403+
# Get all seasons.
404+
all_seasons = seasons(first_match.entry_id)
405+
406+
# Create a dict with episode offers.
407+
id_to_episodes_offers = {
408+
season.season_number: {
409+
episode.episode_number: episode.offers
410+
for episode in episodes(season.entry_id)
411+
}
412+
for season in all_seasons
413+
}
414+
```
415+
416+
417+
### Get offers for multiple countries for all seasons of a TV show
418+
419+
You can combine [`search`](#search-for-a-title),
420+
[`seasons`](#details-for-all-seasons-of-a-tv-show) and
421+
[`offers_for_countries`](#get-offers-for-multiple-countries-for-a-single-title)
422+
functions:
423+
```python
424+
from simplejustwatchapi import offers_for_countries, search, seasons
425+
426+
title = "Andor"
427+
428+
# Search for a title.
429+
search_results = search(title)
430+
431+
# Look for a first match with the expected title.
432+
first_match = next(
433+
result
434+
for result in search_results
435+
if result.title == title and result.object_type == "SHOW"
436+
)
437+
438+
# Get all seasons.
439+
all_seasons = seasons(first_match.entry_id)
440+
441+
# Get offers for each season for each country.
442+
countries = {"US", "DE"}
443+
season_offers = [
444+
offers_for_countries(season.entry_id, countries)
445+
for season in all_seasons
446+
]
447+
448+
# Convert to a dict of country codes to list of offers.
449+
season_offers_per_country = {
450+
country: [
451+
season[country]
452+
for season in season_offers
453+
]
454+
for country in countries
455+
}
456+
```

0 commit comments

Comments
 (0)