123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import requests, os
- def cls_process(path, client_id, one_key, name_column, api_key="sk-iREtaVNjamaBArOTlc_2BfGFJVPiU-9EjSFMUspIPBT3BlbkFJxS0SMmKZD9L9UumPczee4VKawCwVeGBQAr9MgsWGkA",
- proxy=False, chunk_size=100):
- # 定义请求的数据
- data = {
- "path": path,
- "client_id": client_id,
- "one_key": one_key,
- "name_column": name_column,
- "api_key": api_key,
- "proxy": proxy,
- "chunk_size":chunk_size
- }
- # 发送 POST 请求
- response = requests.post("http://10.41.3.69:8070/classify/", json=data)
- # 处理响应
- if response.status_code == 200:
- result = response.json()
- print("接口响应:", result)
- else:
- print(f"请求失败,状态码: {response.status_code}")
- print("错误信息:", response.text)
- def upload_process(file_path, client_id):
- # 表单数据
- data = {
- 'client_id': client_id
- }
- # 发送 POST 请求
- with open(file_path, 'rb') as file:
- name = os.path.basename(file_path)
- files = {
- 'file': (name, file, 'text/plain') # 'text/plain' 是文件类型,可以根据需要修改
- }
- response = requests.post("http://10.41.3.69:8070/uploadfile/", data=data, files=files)
- # 处理响应
- if response.status_code == 200:
- result = response.json()
- print("接口响应:", result)
- return result.get('file_path')
- else:
- print(f"请求失败,状态码: {response.status_code}")
- print("错误信息:", response.text)
- return None
- def both_process(path, client_id, one_key, name_column):
- file_path = upload_process(file_path=path, client_id=client_id)
- if file_path:
- cls_process(path=file_path, client_id=client_id, one_key=one_key, name_column=name_column)
- if __name__ == "__main__":
- both_process(path="E:/code/name_classify/data_before/人群分类-自建站2024.08.xlsx", client_id='wangdalin', one_key='网店单号', name_column='收货姓名')
- # upload_process(file_path="E:/code/name_classify/data_before/人群分类-自建站2024.08.xlsx", client_id='wangdalin')
- # cls_process(path="./process/wangdalin\\人群分类-自建站2024.08.xlsx",client_id='wangdalin', one_key='网店单号', name_column='收货姓名')
|