Exemple #1
0
async def _download_badge(
    badge: Badge,
    *,
    channel: str,
    oauth_token: str,
    client_id: str,
) -> None:
    if os.path.exists(badge.fs_path):
        return

    os.makedirs(BADGE_CACHE, exist_ok=True)

    badges_mapping = collections.ChainMap(
        await channel_badges(
            channel,
            oauth_token=oauth_token,
            client_id=client_id,
        ),
        await global_badges(),
    )
    url = badges_mapping[badge.badge][badge.version]

    async with aiohttp.ClientSession() as session:
        async with session.get(url) as resp:
            data = await resp.read()

    with atomic_open(badge.fs_path) as f:
        f.write(data)
Exemple #2
0
async def _ensure_downloaded(emote: str) -> None:
    emote_path = _emote_path(emote)
    if os.path.exists(emote_path):
        return

    os.makedirs(EMOTE_CACHE, exist_ok=True)

    dl_url = f'https://static-cdn.jtvnw.net/emoticons/v1/{emote}/1.0'
    async with aiohttp.ClientSession() as session:
        async with session.get(dl_url) as resp:
            data = await resp.read()

    with atomic_open(emote_path) as f:
        f.write(data)