def complite_search_genres(call): # Метод, осуществляющий поиск по заданным параментрам в сообщении. all_user_genres = db.get_all_genres_for_user(call.from_user.id, call.message.message_id)[0] logger.debug("TRY TO MAKE SEARCH ON USER " + str(call.from_user.id) + " AND MSG_ID " + str(call.message.message_id)) if len(all_user_genres) > 0: all_user_genres = [ str(j) for j in db.get_all_genres_for_user( call.from_user.id, call.message.message_id)[0] ] else: # TODO: Вывести сообщение о том, что юзер ничего не выбрал через # TODO: оповещения в диалоге. bot.notification return 0 result = api_connection.APIMethods().get_movie_by_params( with_genres=",".join(all_user_genres)) answer_text = complite_results(result) # Формирование текста logger.debug("SEARCH ON USER " + str(call.from_user.id) + " AND MSG_ID " + str(call.message.message_id) + " COMPLITED") bot.edit_message_text(answer_text, call.message.chat.id, call.message.message_id, parse_mode="Markdown") db.destroy_request(call.from_user.id, call.message.message_id) # Удаление запроса из БД.
def format_text(text_obj): # print(text_obj) text_to_return = Smiles.TOP + " *" + text_obj["title"] + "* _(" + text_obj[ "original_title"] + ")_ \n" text_to_return += Smiles.YEAR + " " + text_obj["release_date"] # Разбор случая, если есть предупереждение о возрастном цензе фильма. if text_obj["adult"]: text_to_return += " " + Smiles.NOONE_UNDER_EIGHTEEN + "\n" else: text_to_return += "\n" # Вывод средней оценки. text_to_return += Smiles.STAR + " " + str(text_obj["vote_average"]) + "\n" # Вывод всех жанров фильма genres = text_obj["genre_ids"] text_to_return += Smiles.HISTORY + " " for genre in genres: text_to_return += Genres.num_dict_of_genres[genre] + " / " text_to_return += "\n\n" # Описание фильма text_to_return += text_obj["overview"] url_path = api_connection.APIMethods().get_image_url( text_obj["poster_path"]) text_to_return += "[.](" + url_path + ")" # Необходимо заменять символ, т.к при его отправке возникает ошибка. # Поэтому заменяем на ' return text_to_return.replace("`", "'")
def get_film_by_id(message): film_id = int(re.match(Commands.ID_FILM_RE, message.text).group("film_id")) logger.debug("NEW REQUEST TO FIND FILM BY ID " + str(film_id)) api = api_connection.APIMethods() current_film = api.get_film_by_id(film_id) answer = format_text_one(current_film) is_favorite = True users_favorite_films = db.get_favorite_films(message.chat.id) if users_favorite_films is None: pass elif film_id in users_favorite_films: is_favorite = False if is_favorite: bot.send_message(message.chat.id, answer, parse_mode="Markdown", reply_markup=create_favorite_markup(film_id), disable_web_page_preview=False) else: bot.send_message(message.chat.id, answer, parse_mode="Markdown", reply_markup=create_del_favorite_markup(film_id), disable_web_page_preview=False) db.new_request_count(message.chat.id)
def get_most_popular(message): api = api_connection.APIMethods() most_popular_films = api.get_most_popular() db.new_film_list(message.chat.id, message.message_id, most_popular_films["results"]) logger.debug("NEW REQUEST FOR POPULAR FILMS BY USER " + str(message.chat.id)) f_most_popular_film = most_popular_films["results"][0] answer = format_text(f_most_popular_film) set_favorite = True user_favorite_films = db.get_favorite_films(message.chat.id) if user_favorite_films is None: pass elif f_most_popular_film["id"] in user_favorite_films: set_favorite = False if set_favorite: bot.send_message(message.chat.id, answer, reply_markup=combine_add_favorite_and_slide( f_most_popular_film["id"]), parse_mode="Markdown", disable_web_page_preview=False) else: bot.send_message(message.chat.id, answer, reply_markup=combine_del_favorite_and_slide( f_most_popular_film["id"]), parse_mode="Markdown", disable_web_page_preview=False)
def show_upcoming_films(message): api = api_connection.APIMethods() upcoming = api.get_movie_upcoming() f_upcoming_film = upcoming["results"] f_upcoming_film_text = format_text(f_upcoming_film[0]) db.new_film_list(message.chat.id, message.message_id, f_upcoming_film) logger.debug("NEW REQUEST ON UPCOMING FILMS BY USER ID " + str(message.chat.id)) bot.send_message(message.chat.id, f_upcoming_film_text, parse_mode="Markdown", reply_markup=create_list_movies_inline_keyboard(), disable_web_page_preview=False)
def show_top_films(message): # "" # Метод, выводящий топовые фильмы. # # :param message: # :return: 0 # "" api = api_connection.APIMethods() top_rated = api.get_top_rated() top_rated_results = top_rated["results"] f_top_rated_res = format_text(top_rated_results[0]) f_top_rated_id = top_rated_results[0]["id"] set_favorite = True db.new_film_list(message.chat.id, message.message_id, top_rated_results) user_favorite_films = db.get_favorite_films(message.chat.id) if user_favorite_films is None: pass elif f_top_rated_id in user_favorite_films: set_favorite = False if set_favorite: bot.send_message( message.chat.id, f_top_rated_res, parse_mode="Markdown", reply_markup=combine_add_favorite_and_slide(f_top_rated_id)) else: bot.send_message( message.chat.id, f_top_rated_res, parse_mode="Markdown", reply_markup=combine_del_favorite_and_slide(f_top_rated_id))
def search_film_by_title(message): """ :param message: :return: """ # Определяем переменную для поиска фильма. Т.е выделяем текст из информации по сообщению film_to_find = message.text api = api_connection.APIMethods() logger.debug("NEW REQUEST TO SEARCH FILM") try: result = api.get_movie_by_title(film_to_find) except FilmNotFound: answer = ConstantsAnswers.FILM_NOT_FOUNDED_EDITABLE.format( message.text) image_poster = "" results = ConstantsAnswers.FILM_NOT_FOUNDED_EDITABLE.format( message.text) is_board_active = False else: list_of_results = result["results"] db.new_film_list(message.chat.id, message.message_id, list_of_results) current_result = result["results"][0] image_path = current_result["poster_path"] image_poster = api.get_image_url(image_path) answer = format_text(current_result) results = complite_results(result) bot.send_message(message.chat.id, results, parse_mode="Markdown", disable_web_page_preview=False)