Lastfm now tells you how long ago a user listened to a song
This commit is contained in:
parent
edb5979340
commit
a7299b2aa6
1 changed files with 11 additions and 1 deletions
|
@ -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('l', autohelp=False)
|
||||||
@hook.command(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
|
# the first item is the current track
|
||||||
track = tracks[0]
|
track = tracks[0]
|
||||||
status = 'is listening to'
|
status = 'is listening to'
|
||||||
|
ending = '.'
|
||||||
elif type(tracks) == dict:
|
elif type(tracks) == dict:
|
||||||
# otherwise, they aren't listening to anything right now, and
|
# otherwise, they aren't listening to anything right now, and
|
||||||
# the tracks entry is a dict representing the most recent track
|
# the tracks entry is a dict representing the most recent track
|
||||||
track = tracks
|
track = tracks
|
||||||
status = 'last listened to'
|
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:
|
else:
|
||||||
return "error: could not parse track listing"
|
return "error: could not parse track listing"
|
||||||
|
|
||||||
|
@ -61,6 +68,9 @@ def lastfm(inp, nick='', say=None, db=None, bot=None):
|
||||||
if album:
|
if album:
|
||||||
out += " from the album \x02%s\x0f" % album
|
out += " from the album \x02%s\x0f" % album
|
||||||
|
|
||||||
|
# append ending based on what type it was
|
||||||
|
out += ending
|
||||||
|
|
||||||
if inp and not dontsave:
|
if inp and not dontsave:
|
||||||
db.execute("insert or replace into lastfm(nick, acc) values (?,?)",
|
db.execute("insert or replace into lastfm(nick, acc) values (?,?)",
|
||||||
(nick.lower(), user))
|
(nick.lower(), user))
|
||||||
|
|
Reference in a new issue