From 932a27e5884536900d6d628debdab1d37529537e Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 1 Nov 2015 10:24:44 -0800 Subject: [PATCH] LastFM: catch and fall back to "some point in time" if LastFM's API doesn't show the listened-to date --- LastFM/plugin.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/LastFM/plugin.py b/LastFM/plugin.py index 3c44781..1913944 100644 --- a/LastFM/plugin.py +++ b/LastFM/plugin.py @@ -172,12 +172,14 @@ class LastFM(callbacks.Plugin): if album: album = ircutils.bold("[%s] " % album) - time = int(trackdata["date"]["uts"]) # Time of last listen - # Format this using the preferred time format. - tformat = conf.supybot.reply.format.time() - time = datetime.fromtimestamp(time).strftime(tformat) - irc.reply('%s listened to %s by %s %sat %s' % - (ircutils.bold(user), track, artist, album, time)) + try: + time = int(trackdata["date"]["uts"]) # Time of last listen + # Format this using the preferred time format. + tformat = conf.supybot.reply.format.time() + time = datetime.fromtimestamp(time).strftime(tformat) + except KeyError: # Nothing given by the API? + time = "some point in time" + np = wrap(nowPlaying, [optional("something")])