td_engine_service.py 1.07 KB
Newer Older
lcn's avatar
lcn committed
1 2 3 4 5 6 7 8 9 10 11 12 13
import json
from pot_libs.logger import log
from pot_libs.aiohttp_util.aiohttp_utils import AioHttpUtils
from unify_api.modules.shidianu.service.open_data_service import get_token


async def get_td_engine_data(url, sql):
    token = get_token()
    log.info(f"token:{token},sql:{sql}")
    resp_str, status = await AioHttpUtils().post_data(
        url, data=sql, timeout=50,
        headers={"Authorization": f"Basic {token}"}
    )
ZZH's avatar
ZZH committed
14
    # log.info(f"resp_str:{resp_str},status:{status}")
lcn's avatar
lcn committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    if status != 200:
        return False, None
    results = json.loads(resp_str)
    return True, results


def test_td_engine():
    """
    from unify_api.modules.common.service.td_engine_service import test_td_engine
    test_td_engine()
    """
    from pot_libs.settings import SETTING
    import requests
    token = get_token()
    url = f"{SETTING.stb_url}db_electric"
    print(token)
    h = {"Authorization": f"Basic {token}"}
lcn's avatar
lcn committed
32
    sql = f"select last_row(*) from mt1332_ele where pid=1395"
lcn's avatar
lcn committed
33 34 35 36
    r = requests.post(url, data=sql, headers=h)
    print(r.status_code)
    print(r.content)
    return