
# from datetime import datetime, timezone
# from playwright.async_api import async_playwright, Playwright
# from playwright.sync_api import expect
from playwright.async_api import Playwright, async_playwright, expect
import random
import time
import datetime
import asyncio
import pathlib
import shutil
old_print = print


def timestamped_print(*args, **kwargs):
    old_print(datetime.datetime.utcnow().replace(
        microsecond=0), *args, **kwargs)


print = timestamped_print
print('\n'*5)
print(f"{'{:<6}'.format('ENTER')} {baseclass.scriptfilename} ----------------NOTE-----------NOTE---------------")


def makedirpath(   folder):
    pathlib.Path(folder).mkdir(exist_ok=True)

def rmfolder(  folder):
    if pathlib.Path(folder).exists():
        shutil.rmtree(folder)


# Python中windows路径的3种写法
# 可以是以下这样写：
utc_timeto = int(time.time())
utc_timefrom = int(utc_timeto - 17*24*3600)
utc_timeto = int(utc_timeto + 2*24*3600)

 


async def do_some_thing(playwright      ):

    # browser =  playwright.chromium.launch(headless=True)
    context = await playwright.chromium.launch_persistent_context(user_data_dir=USER_DIR_PATH, accept_downloads=True, headless=False)
    # context = await playwright.firefox.launch_persistent_context(user_data_dir=USER_DIR_PATH, accept_downloads=True, headless=False)
    # context = browser.new_context()
    context.set_default_timeout(9000)
    # context = await browser.new_context()
    arr_page = [None]*2
    arr_page[0] = await context.new_page()
    page = arr_page[0]
    await arr_page[0].goto(
        "https://www.defined.fi/sol/A9KLSS9modWzMc1A189c6HXwy1QkgUupun9TPJZkhmaw?maker=3RTD4pdo5fJ1pu1jAXRAD2Lzxyx4PHLzo2F6M5mP7LGZ&cache=b8081&quoteToken=token1" , timeout=100000)
   
    # cur_arr_str_dalaoAddress =[15]

    print(context.pages)
    await page.wait_for_timeout(100000)
    time.sleep(5.5)
    await page.close()
 

    await context.close()


async def get_onedriver_swapactivities(    ):
    async with async_playwright() as playwright:
        # playwright = Playwright().start()
        await do_some_thing(playwright )


async def main():
    print("enter main()")

    await get_onedriver_swapactivities( )


 
 
# USER_DIR_PATH =    "./browsercookie_path"
USER_DIR_PATH =  baseclass.browsercookie_path   
makedirpath(USER_DIR_PATH)
asyncio.run(main())
# main()
print(f"{'{:<6}'.format('END')}  ----------------NOTE-----------NOTE---------------")
