-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_bot.py
46 lines (31 loc) · 1.5 KB
/
my_bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
from telegram import Update, ParseMode
from telegram.ext import Updater, CommandHandler, CallbackContext
import logging
import moviedb
logging.basicConfig(
level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger()
def hello(update: Update, context: CallbackContext) -> None:
update.message.reply_text(
f"Hello {update.effective_user.first_name}, echo {update.message.text}"
)
def searchmovies(update: Update, context: CallbackContext) -> None:
query = update.message.text.replace("/searchmovies ", "")
movies = moviedb.search_movies(query)
first_three_movies = [movie["original_title"] for movie in movies["results"][:3]]
update.message.reply_text("; ".join(first_three_movies))
def render_movie_by_id(update: Update, context: CallbackContext) -> None:
query = update.message.text.replace("/render_movie_by_id ", "")
reply_message = moviedb.format_movie_by_id(query)
logger.info(reply_message)
update.message.reply_text(r query = update.message.text.replace("/render_movie_by_id ", "")
reply_message = moviedb.format_movie_by_id(query)
logger.info(reply_message)eply_message)
updater = Updater(os.getenv("TELEGRAM_BOT_KEY"))
updater.dispatcher.add_handler(CommandHandler("hello", hello))
updater.dispatcher.add_handler(CommandHandler("searchmovies", searchmovies))
updater.dispatcher.add_handler(CommandHandler("render_movie_by_id", render_movie_by_id))
updater.start_polling()
updater.idle()