From a7299b2aa6860858170c2668c105b7f9d4e9f4ee Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Fri, 27 Apr 2012 00:27:19 +1200 Subject: [PATCH] Lastfm now tells you how long ago a user listened to a song --- plugins/lastfm.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/lastfm.py b/plugins/lastfm.py index 34289f1..b51ae7e 100755 --- a/plugins/lastfm.py +++ b/plugins/lastfm.py @@ -1,4 +1,5 @@ -from util import hook, http +from util import hook, http, timesince +from datetime import datetime @hook.command('l', autohelp=False) @hook.command(autohelp=False) @@ -43,11 +44,17 @@ def lastfm(inp, nick='', say=None, db=None, bot=None): # the first item is the current track track = tracks[0] status = 'is listening to' + ending = '.' elif type(tracks) == dict: # otherwise, they aren't listening to anything right now, and # the tracks entry is a dict representing the most recent track track = tracks status = 'last listened to' + # lets see how long ago they listened to it + time_listened = datetime.fromtimestamp(int(track["date"]["uts"])) + time_since = timesince.timesince(time_listened) + ending = ' (%s ago)' % time_since + else: return "error: could not parse track listing" @@ -60,6 +67,9 @@ def lastfm(inp, nick='', say=None, db=None, bot=None): out += " by \x02%s\x0f" % artist if album: out += " from the album \x02%s\x0f" % album + + # append ending based on what type it was + out += ending if inp and not dontsave: db.execute("insert or replace into lastfm(nick, acc) values (?,?)",