From bad101802c69b8c32296088a1c353f1e6dcce82e Mon Sep 17 00:00:00 2001 From: woni <320753691@qq.com> Date: Fri, 3 Nov 2023 15:56:43 +0800 Subject: [PATCH] add koudai --- koudai.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ tmp.py | 8 +++---- 2 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 koudai.py diff --git a/koudai.py b/koudai.py new file mode 100644 index 0000000..e7b9e7a --- /dev/null +++ b/koudai.py @@ -0,0 +1,69 @@ +import http.client +import json + + +index_mapping = { + "1": {"name": "交易指数", "text": "交易金额"}, + "2": {"name": "流量指数", "text": "访客人数"}, + "3": {"name": "支付转化率指数", "text": "支付转化率"}, + "4": {"name": "客群指数", "text": "支付人数"}, + "5": {"name": "搜索人气", "text": "搜索人数"}, + "6": {"name": "加购人气", "text": "加购人数"}, + "7": {"name": "收藏人气", "text": "收藏人数"}, +} + + +def get_token(username, password): + conn = http.client.HTTPSConnection("www.koudai89.com") + payload = "" + headers = {} + conn.request( + "GET", + f"/web/api/login/doLogin?ursername=&password={password}&username={username}", + payload, + headers, + ) + data = conn.getresponse().read() + data_dict = json.loads(data.decode("utf-8")) + + try: + return data_dict["data"]["login_token"] + except Exception as e: + raise Exception(f"获取token失败: {e}") + + +def reduce_index(token, code, data=int | list) -> int | list: + conn = http.client.HTTPSConnection("www.koudai89.com") + payload_data = [data] if isinstance(data, int) else data + payload_data_list = [{"code": code, "value": item} for item in payload_data] + + payload = json.dumps(payload_data_list) + headers = { + "Content-Type": "application/json", + "user-token": token, + } + conn.request("POST", "/web/api/adviserD/data/select", payload, headers) + response_data = conn.getresponse().read() + data_dict = json.loads(response_data.decode("utf-8")) + + if not data_dict["state"]: + raise Exception(f"获取数据失败: {data_dict['msg']}") + + reduce_data = data_dict["data"] + clear_data = [item.get("result_value") for item in reduce_data] + + if isinstance(data, int): + return clear_data[0] + + return clear_data + + +if __name__ == "__main__": + username = "17756164521" + password = "320753691love" + token = get_token(username, password) + result = reduce_index(token=token, code="1", data=[30000, 10000]) + print(result) + + + diff --git a/tmp.py b/tmp.py index 52f016e..defac16 100644 --- a/tmp.py +++ b/tmp.py @@ -6,10 +6,10 @@ def calculate_y(x): return y -def calculate_x(y): +def reduce_index(index): # Define the function to find the root of def f(x): - return (10 * math.log(x + 1) + 30) * math.sqrt(x) - y + return (10 * math.log(x + 1) + 30) * math.sqrt(x) - index # Set the initial bounds for the bisection method a = 0 @@ -32,6 +32,6 @@ def calculate_x(y): # Example usage -y = 10000000 -x = calculate_y(y) +y = 100000 +x = reduce_index(y) print(x)