nvchecker/nvchecker/source/cratesio.py
lilydjwg 903b414183 cache result during a run
so that different entries can refer to a same software without much overhead.

This is needed because entries may be generated, and only nvchecker can
tell if two entries are expecting the same result because the name may
or may not be relevant.

Closes #81.
2018-10-10 17:03:20 +08:00

15 lines
484 B
Python

# MIT licensed
# Copyright (c) 2013-2018 lilydjwg <lilydjwg@gmail.com>, et al.
from . import session, conf_cacheable_with_name
API_URL = 'https://crates.io/api/v1/crates/%s'
get_cacheable_conf = conf_cacheable_with_name('cratesio')
async def get_version(name, conf, **kwargs):
name = conf.get('cratesio') or name
async with session.get(API_URL % name) as res:
data = await res.json()
version = [v['num'] for v in data['versions'] if not v['yanked']][0]
return version