mirror of
https://github.com/skoobasteeve/useful-scripts.git
synced 2026-03-20 07:28:57 +00:00
it works!!!
This commit is contained in:
@@ -23,15 +23,15 @@ sa_headers = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_args():
|
# def get_args():
|
||||||
parser = argparse.ArgumentParser(
|
# parser = argparse.ArgumentParser(
|
||||||
description='Search movie streaming availability.')
|
# description='Search movie streaming availability.')
|
||||||
|
|
||||||
parser.add_argument('--year', type=int, help='Specify movie release year')
|
# parser.add_argument('--year', type=int, help='Specify movie release year')
|
||||||
return parser.parse_args()
|
# return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def tmdb_lookup(tmdb_url, tmdb_headers, movie, args):
|
def tmdb_lookup(tmdb_url, tmdb_headers, movie):
|
||||||
tmdb_params = {
|
tmdb_params = {
|
||||||
"language": "en-US",
|
"language": "en-US",
|
||||||
"query": movie,
|
"query": movie,
|
||||||
@@ -39,8 +39,8 @@ def tmdb_lookup(tmdb_url, tmdb_headers, movie, args):
|
|||||||
"include_adult": False
|
"include_adult": False
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.year:
|
# if args.year:
|
||||||
tmdb_params["primary_release_year"] = args.year
|
# tmdb_params["primary_release_year"] = args.year
|
||||||
|
|
||||||
tmdb_search = requests.get(f"{tmdb_url}/search/movie", params=tmdb_params,
|
tmdb_search = requests.get(f"{tmdb_url}/search/movie", params=tmdb_params,
|
||||||
headers=tmdb_headers).json()
|
headers=tmdb_headers).json()
|
||||||
@@ -113,8 +113,8 @@ def services_speller(service):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
args = get_args()
|
#args = get_args()
|
||||||
movie = input("Enter a movie: ")
|
#movie = input("Enter a movie: ")
|
||||||
|
|
||||||
movie_id, movie_title, movie_release, movie_rating = tmdb_lookup(
|
movie_id, movie_title, movie_release, movie_rating = tmdb_lookup(
|
||||||
tmdb_url, tmdb_headers, movie, args)
|
tmdb_url, tmdb_headers, movie, args)
|
||||||
@@ -142,5 +142,3 @@ def main():
|
|||||||
print(f"Watch here: {link}\n")
|
print(f"Watch here: {link}\n")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
|||||||
@@ -4,41 +4,92 @@ from telegram.ext import Updater, CommandHandler, CallbackContext, MessageHandle
|
|||||||
import logging
|
import logging
|
||||||
from telegram import Update
|
from telegram import Update
|
||||||
import os
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
import movie_check
|
||||||
|
|
||||||
token = os.environ.get("TG_BOT_TOKEN")
|
tmdb_api_token = os.environ.get("TMDB_API_TOKEN")
|
||||||
|
sa_api_token = os.environ.get("SA_API_TOKEN")
|
||||||
|
|
||||||
updater = Updater(token=token, use_context=True)
|
tmdb_url = "https://api.themoviedb.org/3"
|
||||||
|
tmdb_headers = {
|
||||||
|
'Authorization': f'Bearer {tmdb_api_token}',
|
||||||
|
'Content-Type': 'application/json;charset=utf-8',
|
||||||
|
'Accept': 'application/json;charset=utf-8'
|
||||||
|
}
|
||||||
|
|
||||||
|
sa_url = "https://streaming-availability.p.rapidapi.com/get/basic"
|
||||||
|
sa_headers = {
|
||||||
|
'x-rapidapi-host': "streaming-availability.p.rapidapi.com",
|
||||||
|
'x-rapidapi-key': sa_api_token
|
||||||
|
}
|
||||||
|
|
||||||
|
bot_token = os.environ.get("TG_BOT_TOKEN")
|
||||||
|
|
||||||
|
updater = Updater(token=bot_token, use_context=True)
|
||||||
dispatcher = updater.dispatcher
|
dispatcher = updater.dispatcher
|
||||||
|
|
||||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
level=logging.INFO)
|
level=logging.INFO)
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def start(update: Update, context: CallbackContext):
|
|
||||||
context.bot.send_message(chat_id=update.effective_chat.id, text="I'm a bot, please talk to me!")
|
|
||||||
|
|
||||||
|
# def start(update: Update, context: CallbackContext):
|
||||||
|
# context.bot.send_message(chat_id=update.effective_chat.id, text="I'm a bot, please talk to me!")
|
||||||
|
|
||||||
|
|
||||||
|
# def echo(update: Update, context: CallbackContext):
|
||||||
|
# context.bot.send_message(chat_id=update.effective_chat.id, text=update.message.text)
|
||||||
|
|
||||||
|
|
||||||
|
def movie_lookup(movie):
|
||||||
|
logger.info('movie check started')
|
||||||
|
movie_id, movie_title, movie_year, movie_rating = movie_check.tmdb_lookup(tmdb_url, tmdb_headers, movie)
|
||||||
|
sa_response, services = movie_check.sa_lookup(sa_url, sa_headers, movie_id)
|
||||||
|
tg_reply = f"{movie_title} ({movie_year})\nhttps://themoviedb.org/movie/{movie_id}\nRating: {movie_rating}"
|
||||||
|
|
||||||
|
if not services:
|
||||||
|
tg_reply = tg_reply + "\n\nStreaming not available :("
|
||||||
|
else:
|
||||||
|
for s in services:
|
||||||
|
leaving_epoch = sa_response["streamingInfo"][s]["us"]["leaving"]
|
||||||
|
leaving_date = datetime.fromtimestamp(
|
||||||
|
int(leaving_epoch)).strftime('%Y-%m-%d')
|
||||||
|
link = sa_response["streamingInfo"][s]["us"]["link"]
|
||||||
|
|
||||||
|
s_pretty = movie_check.services_speller(s)
|
||||||
|
tg_reply = tg_reply + f"\n\nAvailable on {s_pretty}"
|
||||||
|
|
||||||
|
if leaving_epoch != 0:
|
||||||
|
tg_reply = tg_reply + f"Will be leaving on {leaving_date}"
|
||||||
|
|
||||||
|
tg_reply = tg_reply + f"\nWatch here: {link}"
|
||||||
|
return tg_reply
|
||||||
|
|
||||||
|
|
||||||
|
# def input_movie(update: Update, context: CallbackContext):
|
||||||
|
# movie = ' '.join(context.args)
|
||||||
|
# # logger.info(movie)
|
||||||
|
# # movie_info = movie_lookup(movie)
|
||||||
|
# context.bot.send_message(chat_id=update.effective_chat.id, text=movie)
|
||||||
|
|
||||||
def echo(update: Update, context: CallbackContext):
|
def echo(update: Update, context: CallbackContext):
|
||||||
context.bot.send_message(chat_id=update.effective_chat.id, text=update.message.text)
|
movie = update.message.text
|
||||||
|
movie_info = movie_lookup(movie)
|
||||||
|
context.bot.send_message(chat_id=update.effective_chat.id, text=movie_info)
|
||||||
def caps(update: Update, context: CallbackContext):
|
|
||||||
text_caps = ' '.join(context.args).upper()
|
|
||||||
context.bot.send_message(chat_id=update.effective_chat.id, text=text_caps)
|
|
||||||
|
|
||||||
|
|
||||||
def unknown(update: Update, context: CallbackContext):
|
def unknown(update: Update, context: CallbackContext):
|
||||||
context.bot.send_message(chat_id=update.effective_chat.id, text="Sorry, I didn't understand that command.")
|
context.bot.send_message(chat_id=update.effective_chat.id, text="Sorry, I didn't understand that command.")
|
||||||
|
|
||||||
|
|
||||||
start_handler = CommandHandler('start', start)
|
# start_handler = CommandHandler('start', start)
|
||||||
dispatcher.add_handler(start_handler)
|
# dispatcher.add_handler(start_handler)
|
||||||
|
|
||||||
echo_handler = MessageHandler(Filters.text & (~Filters.command), echo)
|
echo_handler = MessageHandler(Filters.text & (~Filters.command), echo)
|
||||||
dispatcher.add_handler(echo_handler)
|
dispatcher.add_handler(echo_handler)
|
||||||
|
|
||||||
caps_handler = CommandHandler('caps', caps)
|
# movie_handler = CommandHandler('input_movie', input_movie)
|
||||||
dispatcher.add_handler(caps_handler)
|
# dispatcher.add_handler(movie_handler)
|
||||||
|
|
||||||
unknown_handler = MessageHandler(Filters.command, unknown)
|
unknown_handler = MessageHandler(Filters.command, unknown)
|
||||||
dispatcher.add_handler(unknown_handler)
|
dispatcher.add_handler(unknown_handler)
|
||||||
|
|||||||
Reference in New Issue
Block a user