Merge pull request #4 from skoobasteeve/country-code

country code support
This commit is contained in:
Ray Lyon
2022-04-24 17:26:07 -04:00
committed by GitHub
3 changed files with 9 additions and 3 deletions

View File

@@ -18,6 +18,9 @@ Regardless of how you run it, the program expects the above API tokens to be ava
- **TMDB_API_TOKEN** - **TMDB_API_TOKEN**
- **TG_BOT_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 ### Docker
One-liner: One-liner:
``` ```
@@ -39,6 +42,7 @@ services:
- TMDB_API_TOKEN=${TMDB_API_TOKEN} # Required - TMDB_API_TOKEN=${TMDB_API_TOKEN} # Required
- SA_API_TOKEN=${SA_API_TOKEN} # Required - SA_API_TOKEN=${SA_API_TOKEN} # Required
- TG_BOT_TOKEN=${TG_BOT_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 - TG_BOT_USER= # (optional) Limits access to the bot to a single Telegram user
restart: always restart: always
``` ```

View File

@@ -45,9 +45,9 @@ def tmdb_lookup(tmdb_url, tmdb_headers, movie, year=None):
return movie_id, movie_title, movie_year, movie_rating 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 = { sa_params = {
"country": "us", "country": country,
"tmdb_id": f"movie/{movie_id}", "tmdb_id": f"movie/{movie_id}",
"output_language": "en" "output_language": "en"
} }

View File

@@ -17,6 +17,7 @@ tmdb_api_token = os.environ.get("TMDB_API_TOKEN")
sa_api_token = os.environ.get("SA_API_TOKEN") sa_api_token = os.environ.get("SA_API_TOKEN")
bot_token = os.environ.get("TG_BOT_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") filter_user = os.environ.get("TG_BOT_USER")
tmdb_url = "https://api.themoviedb.org/3" tmdb_url = "https://api.themoviedb.org/3"
@@ -87,7 +88,7 @@ def movie_lookup(movie):
error_response = True error_response = True
return tg_reply, similarity, error_response 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": if sa_response == "404":
logger.info('Movie not found by the Streaming Availability API.') logger.info('Movie not found by the Streaming Availability API.')
@@ -167,6 +168,7 @@ def main():
print("ERROR: Telegram bot token not provided. Exiting...") print("ERROR: Telegram bot token not provided. Exiting...")
exit() exit()
if filter_user: if filter_user:
start_handler = CommandHandler('start', start, start_handler = CommandHandler('start', start,
Filters.user(username=filter_user)) Filters.user(username=filter_user))