def get_tags(cls, refresh=False) -> List[Tag]: """ Return a list of the most popular last.fm tags. The result will be cached for 30 days. \f :rtype: :class:`list` of :class:`pydrag.Tag` """ cls.assert_config() def retrieve_tags(): page = 1 tags = [] # type: List[dict] with spinner("Fetching tags"): while len(tags) < 1000: tags.extend([ t.to_dict() for t in Tag.get_top_tags(limit=250, page=page) ]) page += 1 return tags return [ Tag(**data) for data in Registry.cache( key="last.fm_tag_list", ttl=timedelta(days=30), func=retrieve_tags, refresh=refresh, ) ]
def callme(ttl, value, refresh=False): return Registry.cache( key="foo", ttl=timedelta(seconds=ttl), func=lambda: value, refresh=refresh, )
def get_artist(cls, artist: str) -> Artist: """ Use last.fm api to find an artist by name. The result will be cached for 30 days. :param str artist: The artist's name to lookup :rtype: :class:`pydrag.Artist` """ cls.assert_config() cache = Registry.cache( key="last.fm_artist_{}".format(artist.lower()), ttl=timedelta(days=30), func=lambda: Artist.find(artist).to_dict(), ) return Artist(**cache)
def get_user(cls, username) -> User: """ Use last.fm api to fetch a user by name. The result will be cached for 24 hours. :param str username: The user's name :rtype: :class:`pydrag.User` """ cls.assert_config() cache = Registry.cache( key="last.fm_user_{}".format(username.lower()), ttl=timedelta(hours=24), func=lambda: User.find(username).to_dict(), ) return User(**cache)