Files
F6--/张阳脚本/BI洞察修改前端数据.py
T
2026-01-30 11:28:35 +08:00

157 lines
6.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import pandas as pd
import requests
from pprint import pprint
# 1.获取路径中的数据集位置
def DataNum():
url ="https://insight.f6car.com/api/apps/1000/datasets?offset=0&limit=30&orderBy=createdAt&orderType=desc&meta=false&functions=false&analytic=false&joinExcept=metrics%2Cconnection&requestId=01J9SZ6SZQ92SCQC6RHDMZ7W8X"
cookies_str = '_USER_SESSION_ID=cfecc17c-ab5d-4d78-8aaa-bc4719ddab1f; csrf=5903f3e8-31df-4c1d-84d2-21e89c995b64'
cookies_str = cookies_str.encode('utf-8').decode('latin-1')
cookie_dict = {item.split('=')[0]: item.split('=')[1]
for item in cookies_str.split('; ')}
headers = {
'accept':'application/json',
'accept-encoding':'gzip, deflate, br, zstd',
'accept-language':'zh-CN',
'content-type':'application/json',
'priority':'u=1, i',
# "cookie":"_USER_SESSION_ID=cfecc17c-ab5d-4d78-8aaa-bc4719ddab1f; csrf=5903f3e8-31df-4c1d-84d2-21e89c995b64",
'referer':'https://insight.f6car.com/app/1000/dataset',
'sec-ch-ua':'"Chromium";v="129", "Not;A=Brand";v="8", "Google Chrome";v="129"',
'sec-ch-ua-mobile':'?0',
'sec-ch-ua-platform':'"Windows"',
'sec-fetch-dest':'empty',
'sec-fetch-mode':'cors',
'sec-fetch-site':'same-origin',
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0',
'x-request-domain':'https://insight.f6car.com',
'x-request-hash-url':'https://insight.f6car.com/app/1000/dataset',
'x-request-proxy':'http://localhost:3003'
}
res = requests.get(url,cookies=cookie_dict,headers=headers)
json = res.json()
data = json.get("data") # 获取数据
titles_and_num = {}
for item in data:
if isinstance(item, dict):
title = item.get('title')
dataset = item["execDetail"]["jobParams"]["dataset"]
if title and dataset:
titles_and_num[title]=dataset # 将title与dataset对应存放到字典里
print(titles_and_num)
try:
title_input = input("请输入数据集名字:") # 输入名字“:”是中文符号
dataset = titles_and_num.get(title_input)
return(dataset)
except:
print("数据集不存在")
#2.设置参数
Data_number=DataNum() # 数据集(按创建时间依次类推)
name = "amount_all"# 需要修改的原始字段id
new_message= "数量88883"# 需要修改的目标
key_name = "新22段1" # 新字段名称
function = "12313" #函数方法
type = "number" #字段类型
purpose ="MEASURE" # 字段用途:度量 MEASURE 维度 DIMENSION,通用 null
userComment = "12394654156616241689" # 字段描述
null_format = "1" # empty 0 1 # 只有预设过的好用,不支持自定义
# 非常用变量
cookie = "csrf=756e767f-5bc6-4d2c-af6f-84142e4fe7fb; _USER_SESSION_ID=cfecc17c-ab5d-4d78-8aaa-bc4719ddab1f; pac4jCsrfToken=d06e1f960f12450080e6253a06971dc9"
csrf_token="756e767f-5bc6-4d2c-af6f-84142e4fe7fb"
requestId="01J9R2QGP1MGR7E3GVHS6W3G2R"
headers = {
'accept':'application/json',
'accept-encoding':'gzip, deflate, br, zstd',
'accept-language':'zh-CN',
'content-length':'340',
'content-type':'application/json',
'origin':'https://insight.f6car.com',
'priority':'u=1, i',
'referer':f'https://insight.f6car.com/app/1000/dataset/{Data_number}/fields',#不同数据集需要修改
'cookie':f'{cookie}',#不同数据集内容相同
'sec-ch-ua':'"Chromium";v="129", "Not;A=Brand";v="8", "Google Chrome";v="129"',
'sec-ch-ua-mobile':'?0',
'sec-ch-ua-platform':'"Windows"',
'sec-fetch-dest':'empty',
'sec-fetch-mode':'cors',
'sec-fetch-site':'same-origin',
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0',
'x-csrf-token':f'{csrf_token}',
'x-request-domain':'https://insight.f6car.com',
'x-request-hash-url':f'https://insight.f6car.com/app/1000/dataset/{Data_number}/fields',# 不同数据集需要修改
'x-request-proxy':'http://localhost:3003'
}
# 修改数据方法
def change_message():
json1 = {"datasetId":f"{Data_number}",
"fieldName":f"{name}",
"purpose": f"{purpose}",
"tags":{},
"isMetric":"false","visible":"true",
"label":f"{new_message}",
"type":f"{type}",
"config":{"dialectName":"MysqlDialect",
"formatter":{"number":{"prefix":"","suffix":"","percent":"","unit":"",
"thousands":"false","decimal":2,# 保留小数点位数
"scientificNotation":"false",
"fillInDecimalPlaces":"false","showPlus":"false","showSuffix":"true",
"empty_format":{"type":null_format},
"null_format":{"type":null_format},
"nullReplace":{"kind":"constant","op":null_format,"type":"number"}}}},
"comment":"工单明细id",
"originType":"integer",
"hideValue":"false",
"nativeType":"BIGINT UNSIGNED",
"userComment":f"{userComment}",
"detectedType":"integer",
"suggestedTypes":["number","string","date"],
"defaultAggrType":"sum",
"basicType":"number",
"groupName":"-"}
# request_id = generate_request_id()
# url = 'https://insight.f6car.com/api/apps/1000/datasets/12/field?fieldName=id&requestId=01J9QW3DJAMG81ESXEXZJDE36K' # 工单单据明细url
change_message_url = f"https://insight.f6car.com/api/apps/1000/datasets/{Data_number}/field?fieldName={name}&requestId={requestId}" # 工单测试url
# url2 = "https://insight.f6car.com/api/apps/1000/datasets/3/field?fieldName=id&requestId=01J9R2QGP1MGR7E3GVHS6W3G2R" # 销售单据明细url
# url3 = "https://insight.f6car.com/api/apps/1000/datasets/12/field?fieldName=maintain_detail_id&requestId=01J9T8GTB3A8QYAWYDJT430HAP" # 销售单据明细url
res = requests.put(change_message_url,headers=headers,json=json1)
print(res)
strele = res.json()
print(strele)
# 添加字段方法
def add_key():
add_key_url= f"https://insight.f6car.com/api/apps/1000/datasets/{Data_number}/fields?requestId={requestId}"
data2 = {"options":{"label":f"{key_name}","visible":"true","expr":{"kind":"formula","op":f"{function}","value":f"{function}"}}}
res = requests.post(add_key_url,headers=headers,json=data2)
print(res)
strele = res.json()
print(strele)
change_message()
# add_key()