mirror of
https://github.com/skoobasteeve/telegram-moviebot.git
synced 2026-03-21 20:18:56 +00:00
markdown formatting for reply
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import telegram
|
||||||
from telegram.ext import (
|
from telegram.ext import (
|
||||||
Updater,
|
Updater,
|
||||||
CommandHandler,
|
CommandHandler,
|
||||||
@@ -7,7 +8,7 @@ from telegram.ext import (
|
|||||||
MessageHandler,
|
MessageHandler,
|
||||||
Filters)
|
Filters)
|
||||||
import logging
|
import logging
|
||||||
from telegram import Update
|
from telegram import Update, ParseMode
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import movie_check
|
import movie_check
|
||||||
@@ -57,34 +58,35 @@ def movie_lookup(movie):
|
|||||||
movie_id, movie_title, movie_year, movie_rating = (
|
movie_id, movie_title, movie_year, movie_rating = (
|
||||||
movie_check.tmdb_lookup(tmdb_url, tmdb_headers, movie))
|
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)
|
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}")
|
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:
|
if not services:
|
||||||
tg_reply = tg_reply + "\n\nStreaming not available :("
|
tg_reply = tg_reply + "\n\nStreaming not available :\("
|
||||||
else:
|
else:
|
||||||
for s in services:
|
for s in services:
|
||||||
leaving_epoch = sa_response["streamingInfo"][s]["us"]["leaving"]
|
leaving_epoch = sa_response["streamingInfo"][s]["us"]["leaving"]
|
||||||
leaving_date = datetime.fromtimestamp(
|
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"]
|
link = sa_response["streamingInfo"][s]["us"]["link"]
|
||||||
|
|
||||||
s_pretty = movie_check.services_speller(s)
|
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:
|
if leaving_epoch != 0:
|
||||||
tg_reply = tg_reply + f"Will be leaving on {leaving_date}"
|
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
|
return tg_reply
|
||||||
|
|
||||||
|
|
||||||
def input_movie(update: Update, context: CallbackContext):
|
def input_movie(update: Update, context: CallbackContext):
|
||||||
movie = update.message.text
|
movie = update.message.text
|
||||||
movie_info = movie_lookup(movie)
|
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):
|
def unknown(update: Update, context: CallbackContext):
|
||||||
@@ -99,6 +101,7 @@ def main():
|
|||||||
dispatcher.add_handler(start_handler)
|
dispatcher.add_handler(start_handler)
|
||||||
|
|
||||||
unknown_handler = MessageHandler(Filters.command, unknown)
|
unknown_handler = MessageHandler(Filters.command, unknown)
|
||||||
|
|
||||||
dispatcher.add_handler(unknown_handler)
|
dispatcher.add_handler(unknown_handler)
|
||||||
|
|
||||||
updater.start_polling()
|
updater.start_polling()
|
||||||
|
|||||||
Reference in New Issue
Block a user