Пример #1
0
class FollowedArtistsCommand(FollowArtistMixin, Command):
    """
    Command /followedartists
    Shows a list of the followed artists the request's user
    """
    COMMAND = 'followedartists'

    def __init__(self, update: Update, context: CallbackContext):
        super().__init__(update, context)
        self.telegram_api_client = TelegramAPIClient()
        self.spotify_api_client = SpotifyAPIClient()

    def get_response(self):
        followed_artists_response = self.spotify_api_client.get_followed_artists(self.update.message.from_user.id)
        return self._build_message(followed_artists_response), None

    def _build_message(self, followed_artists_response):
        if not followed_artists_response:
            return self.not_following_any_artist_message

        msg = '<strong>Following artists:</strong> \n'
        for followed_artist in followed_artists_response:
            artist = followed_artist.get('artist')
            msg += f'- {emojis.EMOJI_ARTIST} ' \
                   f'<a href="{artist.get("url")}">{artist.get("name")}</a> ' \
                   f'Followed at: {datetime.datetime.fromisoformat(followed_artist.get("followed_at")).strftime(OUTPUT_DATE_FORMAT)}\n'
        return msg
Пример #2
0
class UnfollowArtistsCommand(FollowArtistMixin, Command):
    """
    Command /unfollowartist
    Shows a list of buttons with followed artists and deletes them when clicking
    """
    COMMAND = 'unfollowartists'

    def __init__(self, update: Update, context: CallbackContext):
        super().__init__(update, context)
        self.spotify_api_client = SpotifyAPIClient()

    def get_response(self):
        keyboard = self._build_keyboard()
        if not keyboard:
            return self.not_following_any_artist_message, None
        return 'Choose an artist to unfollow:', keyboard

    def _build_keyboard(self):
        followed_artists = self.spotify_api_client.get_followed_artists(self.update.message.from_user.id)
        if not followed_artists:
            return None
        return UnfollowArtistButton.get_keyboard_markup(followed_artists)