Exemplo n.º 1
0
async def head(url: str, *args, **kwargs):
    async with session.head(url, *args, **kwargs) as resp:
        try:
            data = await resp.json()
        except Exception:
            data = await resp.text()
    return data
Exemplo n.º 2
0
async def isPreviewUp(preview: str) -> bool:
    for _ in range(7):
        try:
            async with session.head(preview, timeout=2) as resp:
                status = resp.status
                size = resp.content_length
        except asyncio.exceptions.TimeoutError:
            return False
        if status == 404 or (status == 200 and size == 0):
            await asyncio.sleep(0.4)
        else:
            return True if status == 200 else False
    return False
Exemplo n.º 3
0
async def get_http_status_code(url: str) -> int:
    async with aiosession.head(url) as resp:
        return resp.status
Exemplo n.º 4
0
async def file_size_from_url(url: str) -> int:
    async with aiosession.head(url) as resp:
        size = int(resp.headers["content-length"])
    return size