from typing import Awaitable
from typing import Dict
from typing import Any
import aiohttp
import json


async def download_data(url) -> Awaitable[Dict[str, Any]]:
    """The download_data method downloads json data from the `url`.

    Args:
        url (str): the url that the user wants to download

    Returns:
        a dict: {
            'title': 'Kapah haw kisu?',
            'titleCh': '你好嗎？',
            'sentence': [
                {
                    'chinese': '你好嗎，老師？',
                    'order': '1',
                    'word': [
                        {
                            'ab': 'Kapah',
                            'ch': '好'
                        },
                        ...
                    ]
                },
                ...
            ]
        }

    """
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as response:
            while True:
                try:
                    html = await response.json(encoding="utf-8", content_type=None)
                    return html
                    break
                except json.decoder.JSONDecodeError:
                    continue