import json
import os
from pydoc import cli
import sys
import asyncio

SCRIPT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
sys.path.append(SCRIPT_DIR)

import kylinautosolve

CLIENT_KEY = 'w8mp5inwszowft3kyc'

async def main(token: str) -> None:
    if not token:
        print('The acccess token is required.')
        return

    client = kylinautosolve.KylinAutosolveClient()
    client.client_key = CLIENT_KEY
    client.access_token = token

    try:
        client.start()
        await client.when_ready()

        options = {
            'site_key': '6Lfv-q0ZAAAAADy0U9JUaCPCZI15U-7jhbAiYa0U',
            'version': '3',
            'action': 'login',
        }
        create_task_response = await client.invoke(
            client.make_create_task_message(
                kylinautosolve.CreateTaskRequest(
                'google',
                'https://recaptcha-test.kylinbot.io/',
                options.get('timeout', None),
                options)))
        print(create_task_response)

        cancel_response = await client.invoke(
            client.make_cancel_task_message(
                kylinautosolve.CancelTaskRequest(
                    task_id=''
            )))
        print(cancel_response)
    except Exception as e:
        import traceback
        traceback.print_exc()
    finally:
        client.stop()

asyncio.get_event_loop().run_until_complete(main(len(sys.argv) > 1 and sys.argv[1] or ''))
