Changeset 9be02d9 in python-cinema-club-bot for commands/movie.py
- Timestamp:
- Oct 10, 2024, 4:12:00 AM (5 weeks ago)
- Branches:
- master
- Children:
- 8d2d5ac
- Parents:
- 6623428
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
commands/movie.py
r6623428 r9be02d9 13 13 from telegram.ext import ContextTypes 14 14 from imdb import Cinemagoer 15 from pprint import pformat16 15 17 from utils import context_init 18 16 from utils import context_init, choose_next_user 17 from predicates import has_finished_event 19 18 from strings import MOVIE_NOT_PROVIDED, EXPECTED_ONE_MOVIE, \ 20 19 MOVIE_ANOTHER_USER, FETCHING_MOVIE, FETCHING_ERROR, \ 21 MOVIE_REMOVE, MOVIE_SET 20 MOVIE_REMOVE, MOVIE_SET, MOVIES_LIST, NO_MOVIES, ADD_MORE_USERS 22 21 23 22 … … 31 30 context_init(context) 32 31 33 chooser = context.chat_data["users"][0] or None 32 users = context.chat_data["users"] 33 34 if users == []: 35 raise error.TelegramError(ADD_MORE_USERS) 36 37 chooser = users[0] 34 38 username = update.message.from_user.username 39 40 if has_finished_event(context, chooser): 41 users = context.chat_data["users"] = choose_next_user(users) 42 raise error.TelegramError(MOVIE_ANOTHER_USER.format(users[0])) 35 43 36 44 if "@"+username != chooser: … … 51 59 except: 52 60 raise error.TelegramError(FETCHING_ERROR) 53 61 54 62 movie_dict = dict( 55 63 title=movie.data.get("title"), 56 64 id=movie.getID(), 57 65 user=update.effective_user.username, 58 poster=movie.data.get("cover url") 66 poster=movie.data.get("cover url"), 67 rating=movie.data.get("rating"), 68 genres=movie.data.get("genres"), 69 runtime=movie.data.get("runtimes"), 59 70 ) 60 71 … … 76 87 context_init(context) 77 88 78 movies = context.chat_data["movies"].copy() 89 movies = context.chat_data["movies"] 90 91 movies_formatted: str = "" 79 92 80 93 for movie in movies: 81 if movie["poster"] or None: 82 del movie["poster"] 94 movies_formatted += MOVIES_LIST.format( 95 title=movie["title"], 96 id=movie["id"], 97 user=movie["user"] 98 ) 83 99 84 await update.message.reply_text(pformat(movies)) 100 if movies_formatted == "": 101 movies_formatted = NO_MOVIES 102 103 await update.message.reply_text(movies_formatted) 85 104 86 105 … … 101 120 context.chat_data["movies"].remove(movie) 102 121 await update.message.reply_text( 103 MOVIE_REMOVE.format(title=movie["title"], id= ["movie.id"])122 MOVIE_REMOVE.format(title=movie["title"], id=movie["id"]) 104 123 ) 105
Note:
See TracChangeset
for help on using the changeset viewer.