How to use the cachier.cachier function in cachier

To help you get started, we’ve selected a few cachier examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shaypal5 / cachier / tests / test_pickle_core.py View on Github external
@cachier(next_time=False)
def _takes_5_seconds(arg_1, arg_2):
    """Some function."""
    sleep(5)
    return 'arg_1:{}, arg_2:{}'.format(arg_1, arg_2)
github shaypal5 / cachier / tests / test_mongo_core.py View on Github external
@cachier(mongetter=_bad_mongetter)
def _func_w_bad_mongo(arg_1, arg_2):
    """Some function."""
    return random() + arg_1 + arg_2
github shaypal5 / cachier / tests / test_pickle_core.py View on Github external
@cachier(stale_after=timedelta(seconds=1), next_time=True)
def _error_throwing_func(arg1):
    if not hasattr(_error_throwing_func, 'count'):
        _error_throwing_func.count = 0
    _error_throwing_func.count += 1
    if _error_throwing_func.count > 1:
        raise ValueError("Tiny Rick!")
    return 7
github shaypal5 / cachier / tests / test_pickle_core.py View on Github external
@cachier(stale_after=DELTA, next_time=True)
def _stale_after_next_time(arg_1, arg_2):
    """Some function."""
    return random()
github shaypal5 / cachier / tests / test_pickle_core.py View on Github external
@cachier(stale_after=DELTA, next_time=False)
def _stale_after_seconds(arg_1, arg_2):
    """Some function."""
    return random()
github shaypal5 / cachier / tests / test_pickle_core.py View on Github external
@cachier(stale_after=timedelta(seconds=1), next_time=True)
def _being_calc_next_time(arg_1, arg_2):
    """Some function."""
    sleep(1)
    return random() + arg_1 + arg_2
github ChenghaoMou / touchbar-lyric / Lyric.py View on Github external
@cachier(stale_after=datetime.timedelta(days=3))
def get_id(name, artists):
    url = f"https://music.aityp.com/search?keywords={name}"
    headers = {
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}

    r = requests.get(url, headers=headers)
    data = r.json()
    ids = []
    if 'songs' in data['result']:
        for song in data['result']['songs']:
            if 'artists' in song:
                # print(song)
                name = re.findall('([a-z A-Z]+)', song['artists'][0]['name'])
                if name:
                    name = name[0]
                    name = name.replace(' ', '').lower()
github BradenM / micropy-cli / micropy / utils / helpers.py View on Github external
@cachier(stale_after=timedelta(days=1))
def ensure_valid_url(url):
    """Ensure a url is valid.

    Args:
        url (str): URL to validate

    Raises:
        InvalidURL: URL is not a valid url
        ConnectionError: Failed to connect to url
        HTTPError: Reponse was not 200 

    Returns:
        str: valid url

    """
    if not is_url(url):
github korymath / talk-generator / talkgenerator / sources / pixabay.py View on Github external
@cachier(cache_dir=Path("..", "tmp").absolute())
def search_photos(query, orientation="all") -> List[ImageData]:
    if pixabay_session:
        results = pixabay_session.search(q=query, orientation=orientation)
        if results and results["hits"]:
            images = []
            for photo in results["hits"]:
                link_download = photo["largeImageURL"]
                creator = photo["user"] + " (via Pixabay)" if "user" in photo else None
                images.append(ImageData(image_url=link_download, source=creator))
            return images
        else:
            logger.warning(
                'Pixabay could not find results for "{}", which might be due to missing/erroneous access keys'.format(
                    query
                )
            )
github korymath / talk-generator / talkgenerator / sources / phrasefinder.py View on Github external
@cachier(cache_dir=Path("..", "tmp").absolute())
def _search(word):
    word.replace(" ", "%20")
    url = URL.format(word)
    try:
        result = requests.get(url)
        result = result.json()
        if result:
            return result["phrases"]
    except JSONDecodeError:
        return None