element_music_bot

An element chatbot written in Python.
Log | Files | Refs | README

commit 7ae3b1bb86e81e7239c6aeb42bc2a500d63a7bb7
parent 475cca2caaf1934b98937453e96622c89dc07bd3
Author: John Kubach <johnkubach@gmail.com>
Date:   Tue, 11 Aug 2020 17:23:53 -0400

Fix Crash On LastFM Artist Not Found

Diffstat:
Mfunctions/extract_info.py | 21++++++++++++++-------
Mmusic.py | 5+++--
2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/functions/extract_info.py b/functions/extract_info.py @@ -22,15 +22,22 @@ def get_artist_song(title): return artist, song def get_artist_info(artist): - info = lastfm_network.get_artist(artist).get_bio_summary() + try: + info = lastfm_network.get_artist(artist).get_bio_summary() + except pylast.WSError as e: + info = None + return info def get_tags(artist): - info = lastfm_network.get_artist(artist).get_top_tags(limit=2) - genre_list = [] - for t in info: - genre_list.append(t.item.get_name()) - - format_tags = ', '.join(genre_list) + try: + info = lastfm_network.get_artist(artist).get_top_tags(limit=2) + genre_list = [] + for t in info: + genre_list.append(t.item.get_name()) + + format_tags = ', '.join(genre_list) + except pylast.WSError as e: + format_tags = None return format_tags diff --git a/music.py b/music.py @@ -42,8 +42,9 @@ def youtube(event): tags = get_tags(artist) bio = get_artist_info(artist) - song_info.append("Genre: " + tags) - song_info.append(re.sub('<.*?>', '', bio)) + if tags and bio: + song_info.append("Genre: " + tags) + song_info.append(re.sub('<.*?>', '', bio)) return song_info