Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from util import hook, http, timesince
- from datetime import datetime
- api_url = "http://ws.audioscrobbler.com/2.0/?format=json"
- @hook.command('plays', autohelp=False)
- @hook.command(autohelp=False)
- def plays(inp, nick='', db=None, bot=None, notice=None):
- """plays [user] [band] -- Displays the number of times [user] has listened $
- api_key = bot.config.get("api_keys", {}).get("lastfm")
- if not api_key:
- return "error: no api key set"
- db.execute("create table if not exists lastfm(nick primary key, acc)")
- if not user:
- user = db.execute("select acc from lastfm where nick=lower(?)",
- (nick,)).fetchone()
- if not user:
- notice(lastfm.__doc__)
- return
- user = user[0]
- response = http.get_json(api_url, method="user.getartisttracks",
- api_key=api_key, user=user, limit=1)
- if 'error' in response:
- return "Error: {}.".format(response["message"])
- if not "items" in response["artisttracks"] or (response["artisttracks"]["@a$
- return '"{}" has never listened to that band.'.format(user)
- plays = response["artisttracks"]["@attr"]["items"]
- out = '{} {} {} {}'.format(user, status, plays, artist)
- if artist:
- out += " by \x02{}\x0f".format(artist)
- # append ending based on what type it was
- out += ending
- return out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement