From 31ebe358d517de917c8f4b0f177dcc389daf96a8 Mon Sep 17 00:00:00 2001 From: Ray Lyon Date: Sun, 24 Apr 2022 17:25:47 -0400 Subject: [PATCH] country code support --- README.md | 4 ++++ telegram-moviebot/movie_check.py | 4 ++-- telegram-moviebot/telegram-moviebot.py | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0a80b2c..1d04312 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ Regardless of how you run it, the program expects the above API tokens to be ava - **TMDB_API_TOKEN** - **TG_BOT_TOKEN** +Optional environment variables: +- **STREAMING_COUNTRY** (default "us") - Choose any ISO 3166 country code supported by the [Sreaming Availability API](https://rapidapi.com/movie-of-the-night-movie-of-the-night-default/api/streaming-availability/) + ### Docker One-liner: ``` @@ -39,6 +42,7 @@ services: - TMDB_API_TOKEN=${TMDB_API_TOKEN} # Required - SA_API_TOKEN=${SA_API_TOKEN} # Required - TG_BOT_TOKEN=${TG_BOT_TOKEN} # Required + - STREAMING_COUNTRY= # (optional) Default "us" - TG_BOT_USER= # (optional) Limits access to the bot to a single Telegram user restart: always ``` diff --git a/telegram-moviebot/movie_check.py b/telegram-moviebot/movie_check.py index 05d3d11..ec165cc 100644 --- a/telegram-moviebot/movie_check.py +++ b/telegram-moviebot/movie_check.py @@ -45,9 +45,9 @@ def tmdb_lookup(tmdb_url, tmdb_headers, movie, year=None): return movie_id, movie_title, movie_year, movie_rating -def sa_lookup(sa_url, sa_headers, movie_id): +def sa_lookup(sa_url, sa_headers, movie_id, country): sa_params = { - "country": "us", + "country": country, "tmdb_id": f"movie/{movie_id}", "output_language": "en" } diff --git a/telegram-moviebot/telegram-moviebot.py b/telegram-moviebot/telegram-moviebot.py index acf3ed3..b3cb274 100644 --- a/telegram-moviebot/telegram-moviebot.py +++ b/telegram-moviebot/telegram-moviebot.py @@ -17,6 +17,7 @@ tmdb_api_token = os.environ.get("TMDB_API_TOKEN") sa_api_token = os.environ.get("SA_API_TOKEN") bot_token = os.environ.get("TG_BOT_TOKEN") +country = os.environ.get("STREAMING_COUNTRY") or "us" filter_user = os.environ.get("TG_BOT_USER") tmdb_url = "https://api.themoviedb.org/3" @@ -87,7 +88,7 @@ def movie_lookup(movie): error_response = True return tg_reply, similarity, error_response - sa_response, services = movie_check.sa_lookup(sa_url, sa_headers, movie_id) + sa_response, services = movie_check.sa_lookup(sa_url, sa_headers, movie_id, country) if sa_response == "404": logger.info('Movie not found by the Streaming Availability API.') @@ -167,6 +168,7 @@ def main(): print("ERROR: Telegram bot token not provided. Exiting...") exit() + if filter_user: start_handler = CommandHandler('start', start, Filters.user(username=filter_user))