def now_playing(self, cardinal, user, channel, msg):
        # Before we do anything, let's make sure we'll be able to query Last.fm
        if self.api_key is None:
            cardinal.sendMsg(
                channel,
                "Last.fm plugin is not configured. Please set API key."
            )
            self.logger.error(
                "Attempt to get now playing failed, API key not set"
            )
            return

        if not self.conn:
            cardinal.sendMsg(
                channel,
                "Unable to access local Last.fm database."
            )
            self.logger.error(
                "Attempt to get now playing failed, no database connection"
            )
            return

        # Open the cursor for the query to find a saved Last.fm username
        c = self.conn.cursor()

        message = msg.split()

        # If using natural syntax, remove Cardinal's name
        if message[0] != '.np' and message[0] != '.nowplaying':
            message.pop(0)

        # If they supplied user parameter, use that for the query instead
        if len(message) >= 2:
            nick = message[1]
            c.execute("SELECT username FROM users WHERE nick=?", (nick,))
        else:
            nick = user.group(1)
            vhost = user.group(3)
            c.execute(
                "SELECT username FROM users WHERE nick=? OR vhost=?",
                (nick, vhost)
            )
        result = c.fetchone()

        # Use the returned username, or the entered/user's nick otherwise
        if not result:
            try:
                username = message[1]
            except __HOLE__:
                username = user.group(1)
        else:
            username = result[0]

        try:
            uh = urllib2.urlopen(
                "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks"
                "&user=%s&api_key=%s&limit=1&format=json" %
                (username, self.api_key)
            )
            content = json.load(uh)
        except Exception:
            cardinal.sendMsg(channel, "Unable to connect to Last.fm.")
            self.logger.exception("Failed to connect to Last.fm")
            return

        if 'error' in content and content['error'] == 10:
            cardinal.sendMsg(
                channel,
                "Last.fm plugin is not configured. Please set API key."
            )
            self.logger.error(
                "Attempt to get now playing failed, API key incorrect"
            )
            return
        elif 'error' in content and content['error'] == 6:
            cardinal.sendMsg(
                channel,
                "Your Last.fm username is incorrect. No user exists by the "
                "username %s." % str(username)
            )
            return

        try:
            song = content['recenttracks']['track'][0]['name']
            artist = content['recenttracks']['track'][0]['artist']['#text']

            cardinal.sendMsg(
                channel,
                "%s is now listening to: %s by %s" %
                (str(username), str(song), str(artist))
            )
        except IndexError:
            cardinal.sendMsg(
                channel,
                "Unable to find any tracks played. "
                "(Is your Last.fm username correct?)"
            )
dataset/ETHPy150Open JohnMaguire/Cardinal/plugins/lastfm/plugin.py/LastfmPlugin.now_playing