<commit_before># -*- coding: utf-8 -*-
from shiva.utils import ignored, get_logger

log = get_logger()


class LastFM(object):
    def __init__(self, api_key, use_cache=True):
        """
        Wrapper around LastFM's library, pylast. Simplifies handling and adds
        caching.

        Cache's schema:
            self.cache[artist.name]
            self.cache[artist.name]['object']
            self.cache[artist.name]['albums']
            self.cache[artist.name]['albums'][album.name]
        """
        import pylast

        self.pylast = pylast
        self.use_cache = use_cache
        self.lib = self.pylast.LastFMNetwork(api_key=api_key)
        self.cache = {}

    def get_artist(self, name):
        artist = self.cache.get(name, {}).get('object')

        if not artist:
            with ignored(Exception, print_traceback=True):
                log.debug('[ Last.FM ] Retrieving artist "%s"' % name)
                artist = self.lib.get_artist(name)
            if artist and self.use_cache:
                self.cache.update({
                    name: {
                        'object': artist
                    }
                })

        return artist<commit_msg>Moved log message outside try block<commit_after># -*- coding: utf-8 -*-
from shiva.utils import ignored, get_logger

log = get_logger()


class LastFM(object):
    def __init__(self, api_key, use_cache=True):
        """
        Wrapper around LastFM's library, pylast. Simplifies handling and adds
        caching.

        Cache's schema:
            self.cache[artist.name]
            self.cache[artist.name]['object']
            self.cache[artist.name]['albums']
            self.cache[artist.name]['albums'][album.name]
        """
        import pylast

        self.pylast = pylast
        self.use_cache = use_cache
        self.lib = self.pylast.LastFMNetwork(api_key=api_key)
        self.cache = {}

    def get_artist(self, name):
        artist = self.cache.get(name, {}).get('object')

        if not artist:
            log.debug('[ Last.FM ] Retrieving artist "%s"' % name)
            with ignored(Exception, print_traceback=True):
                artist = self.lib.get_artist(name)
            if artist and self.use_cache:
                self.cache.update({
                    name: {
                        'object': artist
                    }
                })

        return artist
{'fraction_non_alphanumeric': 0.11461794019933555, 'fraction_numerical': 0.0008305647840531562, 'mean_word_length': 1.7312925170068028, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7356105', 'n_tokens_mistral': 714, 'n_tokens_neox': 684, 'n_words': 146}