-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmov.py
81 lines (55 loc) · 2.5 KB
/
mov.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from telegram import Update
import telegram
import logging
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
from dotenv import load_dotenv
import os
from omdb import movie_infor
load_dotenv()
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
Token = os.getenv("Token")
def start(update: Update, context: CallbackContext) -> None:
update.message.reply_text(
"Hi! Am a movie bot"
+ "\nI gives brief information about any movie from OMDb website."
+ "\nSend any movie name and get brief info about the year,actors, plot and ratings "
+ "from IMDb, Rotten Tomatoes, Metacritic and Internet Movie Database \nUse the command /help if you need any help."
+ "\nHave fun playing around")
def help_command(update: Update, context: CallbackContext) -> None:
update.message.reply_text("This is a movie rating bot,"
+ "\nJust enter the movie name and get brief info about the year,actors, plot and ratings. "
+ " For example 'ip man' and send to get info."
+ "\nHave fun playing around")
def search(update: Update, context: CallbackContext):
movie_name = update.message.text
movie_info =movie_infor(movie_name)
message = ""
if movie_info:
rating_text = f"IMDb Rating: {movie_info['imdb_ratings']}\n"
for rating in movie_info['ratings']:
rating_text += f"{rating['Source']}: {rating['Value']}\n"
message = (f"{movie_info['title']} ({movie_info['year']}): \n\n" +
f"Plot:\n{movie_info['plot']}\n\n" +
f"Starring:\n{movie_info['actors']}\n\n" +
f"Ratings:\n{rating_text}"
f"Poster:\n{movie_info['poster']}\n\n"
)
else:
message = f"Moive '{movie_name} not found on the omdb site, Please check you spelling errors and try again"
update.message.reply_text(text=message)
def error(update:Update, context:CallbackContext):
update.message.reply_text("An Error occured")
def main():
updater = Updater(Token)
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler("start", start))
dispatcher.add_handler(CommandHandler("help", help_command))
infor_handler = MessageHandler(Filters.text, search)
dispatcher.add_handler(infor_handler)
dispatcher.add_error_handler(error)
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()