mirror of
https://github.com/skoobasteeve/telegram-moviebot.git
synced 2026-03-20 03:28:57 +00:00
markdown formatting for reply
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import telegram
|
||||
from telegram.ext import (
|
||||
Updater,
|
||||
CommandHandler,
|
||||
@@ -7,7 +8,7 @@ from telegram.ext import (
|
||||
MessageHandler,
|
||||
Filters)
|
||||
import logging
|
||||
from telegram import Update
|
||||
from telegram import Update, ParseMode
|
||||
import os
|
||||
from datetime import datetime
|
||||
import movie_check
|
||||
@@ -57,34 +58,35 @@ def movie_lookup(movie):
|
||||
movie_id, movie_title, movie_year, movie_rating = (
|
||||
movie_check.tmdb_lookup(tmdb_url, tmdb_headers, movie))
|
||||
|
||||
movie_rating = str(movie_rating).replace('.', '\.')
|
||||
sa_response, services = movie_check.sa_lookup(sa_url, sa_headers, movie_id)
|
||||
tg_reply = (f"{movie_title} ({movie_year})\n{tmdb_page}{movie_id}" +
|
||||
tg_reply = (f"{movie_title} \({movie_year}\)\n[TMDB]({tmdb_page}{movie_id})" +
|
||||
f"\nRating: {movie_rating}")
|
||||
logger.info(f'Returning movie: "{movie_title}: ({movie_year})"')
|
||||
logger.info(f'Returning movie: "{movie_title}: \({movie_year}\)"')
|
||||
|
||||
if not services:
|
||||
tg_reply = tg_reply + "\n\nStreaming not available :("
|
||||
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')
|
||||
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}"
|
||||
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}"
|
||||
tg_reply = tg_reply + f"\n[Watch here]({link})"
|
||||
return tg_reply
|
||||
|
||||
|
||||
def input_movie(update: Update, context: CallbackContext):
|
||||
movie = update.message.text
|
||||
movie_info = movie_lookup(movie)
|
||||
context.bot.send_message(chat_id=update.effective_chat.id, text=movie_info)
|
||||
context.bot.send_message(chat_id=update.effective_chat.id, text=movie_info, parse_mode=telegram.ParseMode.MARKDOWN_V2)
|
||||
|
||||
|
||||
def unknown(update: Update, context: CallbackContext):
|
||||
@@ -99,6 +101,7 @@ def main():
|
||||
dispatcher.add_handler(start_handler)
|
||||
|
||||
unknown_handler = MessageHandler(Filters.command, unknown)
|
||||
|
||||
dispatcher.add_handler(unknown_handler)
|
||||
|
||||
updater.start_polling()
|
||||
|
||||
Reference in New Issue
Block a user