from datetime import datetime
from pprint import pprint
import asyncio


async def fetch(url, worker):
    """Navigate to page at 'url' and log metadata."""
    resp = await worker.try_get(url)
    html = await worker.page.content()
    title = await worker.page.xpath('//title')
    if title:
        title = await worker.page.evaluate('(ele) => ele.innerText', title[0])
    data = {
        'url': worker.page.url,
        'status': resp.status if resp else None,
        'title': title or None,
        'time': str(datetime.now()),
    }
    pprint(data)
    return data


async def sleep_return_1(sleep_time: float) -> int:
    await asyncio.sleep(sleep_time)
    return 1
