from DrissionPage import ChromiumPage, ChromiumOptions

from bit_tools import openBrowser
from models.weex import Weex1, Weex1Hour

if __name__ == '__main__':

    bit_port = openBrowser(id="8dcb4f744cf64ab190e465e153088515")

    co = ChromiumOptions()
    co.set_local_port(port=bit_port)

    co = ChromiumOptions()
    co.set_local_port(bit_port)

    page = ChromiumPage(addr_or_opts=co)

    page.set.window.max()

    page.listen.start("https://http-gateway1.janapw.com/api/v1/public/quote/v1/getKlineV2")

    page.get(url="https://www.weeaxs.site/zh-CN/futures/ETH-USDT")

    for _ in range(10000):
        res = page.listen.wait()  # 等待并获取一个数据包

        print(_)
        print(res.response.url)

        for data in res.response.body['data']["dataList"]:
            Weex1Hour.get_or_create(
                id=int(data[4]),
                defaults={
                    'open': float(data[3]),
                    'high': float(data[1]),
                    'low': float(data[2]),
                    'close': float(data[0]),
                }
            )
