def render_library_button(self, bot, query, chat_id): """ Отображение библиотеки пользователя Args: bot (:class:`telegram.Bot`): хэндлер бота query (:class:`telegram.CallbackQuery`): возвращаемое значение от inline клавиатуры chat_id (:obj:`int`) id пользователя """ postgre = DataBase() flags[chat_id] = Flags() flags[chat_id].set_library(postgre.GetUserLibrary(chat_id)) library = flags[chat_id].get_library() if library == {}: bot.edit_message_text( text=Settings.EmptyLibraryTxt, chat_id=chat_id, message_id=query.message.message_id, ) return text_out = "http://imdb.com/title/tt%s" % library[0][1] series_info = postgre.GetSeriesInfo(library[0][1]) if (series_info): text_out += "\n *Season* - %s *Episode* - %s" % ( series_info['season'], series_info['episode']) reply_markup = library_navigate_markup(len(library)) bot.edit_message_text(text=text_out, chat_id=chat_id, message_id=query.message.message_id, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN) logger.info("rendered library list for %s " % chat_id)
def delete_title_from_library_button(self, bot, query, chat_id): """ Кнопка для удаления фильма из библиотеки Args: bot (:class:`telegram.Bot`): хэндлер бота query (:class:`telegram.CallbackQuery`): возвращаемое значение от inline клавиатуры chat_id (:obj:`int`) id пользователя """ index = int(query.data.split("_")[1]) data = flags[chat_id].get_library() logger.info("deleting %s" % data[index][1]) postgre = DataBase() postgre.DeleteFilmFromLibrary(chat_id, data[index][1]) flags[chat_id] = Flags() flags[chat_id].set_library(postgre.GetUserLibrary(chat_id)) dic = flags[chat_id].get_library() print(dic) if dic == {}: bot.edit_message_text(text=Settings.EmptyLibraryTxt, chat_id=chat_id, message_id=query.message.message_id) return index = index % len(dic) text_out = "http://imdb.com/title/tt%s" % dic[index][1] series_info = postgre.GetSeriesInfo(dic[index][1]) if (series_info): text_out += "\n *Season* - %s *Episode* - %s" % ( series_info['season'], series_info['episode']) reply_markup = library_navigate_markup(len(dic), index) bot.edit_message_text(text=text_out, chat_id=chat_id, message_id=query.message.message_id, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN)