add koudai
This commit is contained in:
1 parent
7177a07538
commit
bad101802c
2 files changed
+73
-4
No files matched your search
@@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -6,10 +6,10 @@ def calculate_y(x):
|
|||||||
return y
|
return y
|
||||||
|
|
||||||
|
|
||||||
def calculate_x(y):
|
def reduce_index(index):
|
||||||
# Define the function to find the root of
|
# Define the function to find the root of
|
||||||
def f(x):
|
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
|
# Set the initial bounds for the bisection method
|
||||||
a = 0
|
a = 0
|
||||||
@@ -32,6 +32,6 @@ def calculate_x(y):
|
|||||||
|
|
||||||
|
|
||||||
# Example usage
|
# Example usage
|
||||||
y = 10000000
|
y = 100000
|
||||||
x = calculate_y(y)
|
x = reduce_index(y)
|
||||||
print(x)
|
print(x)
|
||||||
Reference in new issue
Block a user