59 KiB
59 KiB
In [ ]:
import pandas as pd import requests from login_for_cookie import Vc import pendulum import json from utils/gtools import MySQLconnect from lxml import etree from pathlib import Path from datetime import datetime cookie = Vc(user='robot1',pswd= 'xi%26SiH4LbJ') headers = {"Cookie":cookie}
In [ ]:
def get_fs(row): data = row["采购单号"] buy_url = "http://cp.maso.hk/index.php?main=store_in_receive" payload = { "s_pid": 2867159, "s_suborderid": "", "pdt_standard_id": "", "s_store": -1, "s_status[0]": 0, "s_sort": "desc", "Submit": "查询", "synergy_sign": -1, "start_dep": "", "start_user": "", "to_dep": "", "to_user": "", "swebid": 0, "local_pdt_id": 0, "sadd_time": "", "sadd_time_end": "", "sreal_express_no": "", "sweb_id": "", "sof": 0, "soe": 0, "sod": "", "tsid": -1, "tsdid": -1, "tsst": -1, "order_cate": -1, "error_status": -1, "web_uid": -1, "team_id": -1, "handle": -1, "handle_uid": 0, "handle_time_start": "", "handle_time_end": "", "shiping_time_start": "", "shiping_time_end": "", "trade_time_start": "", "trade_time_end": "", "order_express_fee": -1, "web_type": -1, "shipping_type": -1, "maintain_add_time_s": "", "maintain_add_time_e": "", "maintain_comfirm_time_s": "", "maintain_comfirm_time_e": "", "dispense_user_id": "", "export_page": 1 } payload["s_pid"] = data resp = requests.post(url = buy_url ,headers=headers , data=payload) buy_df_list = pd.read_html(resp.text,match="所属网站ID") buy_df = buy_df_list[1] buy_df.columns = buy_df.loc[0,:] trade_id = buy_df["交易ID"][1] #交易明细里头 trade_url = f"http://cp.maso.hk/index.php?main=store_tradelist_info&trade_id={trade_id}" resp2 = requests.get(url = trade_url ,headers=headers ) df_list2 = pd.read_html(resp2.text,match="下单发货时间") df2 = df_list2[0] df2.columns = df2.loc[0,:] 下单发货时间 = int(df2.iloc[2,1][0].replace("--","0")) 维护发货时间 = int(df2.iloc[2,3].replace("--","0")) 支付时间 = pendulum.parse(df2.iloc[3,3]) 最大发货时间 = 支付时间.add(days=max(下单发货时间,维护发货时间)) #交易列表 trade_list_url = f"http://cp.maso.hk/index.php?main=store_in_receive&navlist=trade_list&s_trade_id={trade_id}" resp3 = requests.get(url = trade_list_url ,headers=headers ) df_list3 = pd.read_html(resp3.text,match="涨幅") df3 = df_list3[0] df3.columns = df3.loc[0,:] 交易平台 = df3["交易平台"][1] 交易号 = df3["交易号"][1] 交易平台订单号 = df3["交易平台订单号"][1] return pd.Series([trade_id,下单发货时间, 维护发货时间,支付时间,最大发货时间,交易平台,交易号,交易平台订单号])
In [ ]:
resultdf = pd.read_excel(r"跟单测试源文件.xlsx")[["跟单任务ID", "采购单号"]] # 扩展 get_fs fs_cols = resultdf.apply(lambda x: get_fs(x), axis=1, result_type="expand") fs_cols.columns = ["交易ID",'下单发货时间', '维护发货时间','支付时间','最大发货时间','交易平台','交易号','交易平台订单号'] resultdf = pd.concat([resultdf, fs_cols], axis=1) # 处理日期 for col in ['支付时间', '最大发货时间']: resultdf[col] = pd.to_datetime(resultdf[col], errors='coerce') resultdf[col] = resultdf[col].dt.strftime('%Y-%m-%d') resultdf['pay_date'] = resultdf['支付时间'] # POST data = resultdf.to_dict(orient='records') headers = {"Content-Type": "application/json; charset=utf-8"} url = "http://192.168.100.44/rpaapi/followup" response = requests.post(url, headers=headers, data=json.dumps(data)) print("状态码:", response.status_code) print("响应内容:", response.json())
In [ ]:
mdm = MySQLconnect("mdm") #对数据库进行创建TASK,这个应该放在后端 def create_first_task(): all_sql = "select * from tw_order_follow_up WHERE platform = '淘天' AND length(trade_platform_order_num) >=12" df = pd.read_sql(all_sql, mdm.engine()) for idx,row in df.iterrows(): trade_id = row["trade_id"] max_logis_date_mmdd =row["max_logis_date"] mmdd = f"{max_logis_date_mmdd.month}月{max_logis_date_mmdd.day}日" send_text = f"平台交易号:{trade_id},你好,请问最快什么时候发货,{mmdd}前可以发货吗?" task_url = "http://192.168.100.44/rpaapi/taskcreate" headers = { "Content-Type": "application/json; charset=utf-8", # 指定 UTF-8 编码 "Other-Header": "value" } response = requests.post(url=task_url, headers=headers, data=json.dumps({"task_type":"跟单","type_id":row["cpmaso_task_id"],"send_content":send_text,"level":"level1"})) create_first_task() #这里是写到影刀里面的 def get_tw_url(task_id): url = f"http://192.168.100.44/rpaapi/get_url/{task_id}" response = requests.get(url=url).json() return response def finish_task(task_id,task_status,session_id): task_url = "http://192.168.100.44/rpaapi/taskfinish" response = requests.post(url=task_url, headers=headers, data=json.dumps({"task_id":task_id,"task_status":task_status,"session_id":session_id})) return response.json()
In [ ]:
In [ ]:
#以下内容也全都写到影刀里面 file = Path(r"C:\Users\Admin\Desktop\taoworldtask.txt") def html_to_db(html): # -> list[dict] tree = etree.HTML(html) container = tree.xpath("//*[contains(@class, 'IMChat--ww_container--rcKMqZZ')]")[0] shopname = container.xpath("//*[contains(@class, 'IMChat--ww_header--qyQJ4Lp')]/text()")[0].strip() message_item_lines = container.xpath("//*[contains(@class, 'message-item-lin')]") results = [] for msg in message_item_lines: message_id = msg.get('id', '') # 昵称 nick_x = msg.xpath(".//div[contains(@class, 'nick')]/text()") nick = nick_x[0].strip() if nick_x else '' # 时间 time_x = msg.xpath(".//div[contains(@class, 'time')]/text()") time_str = time_x[0].strip() if time_x else '' try: time = datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S") if time_str else None except ValueError: time = None # 内容或图片 content_x = msg.xpath(".//pre[contains(@class, 'edit')]/text()") content = ','.join(content_x).strip() if content_x else '' img_x = msg.xpath(".//img[contains(@class, 'imui-msg-img')]/@src") if img_x: content = img_x[0] # 可考虑记录 chat_type='image' result = { 'id': message_id, 'nick': nick, 'time': time.strftime("%Y-%m-%d %H:%M:%S") if time else None, 'content': content } results.append(result) return { "shopname": shopname, "messages": results } def upload_msg(msg_list, account, create_chat_id=''): url = "http://192.168.100.44/rpaapi/upload_msg" payload = { "shopname": msg_list["shopname"], "messages": msg_list["messages"], "account": account, "creata_chat_id": create_chat_id # 如果为空,表示接收方;否则为发送者创建会话用 } headers = { "Content-Type": "application/json" } try: resp = requests.post(url, headers=headers, data=json.dumps(payload)) if resp.status_code == 200: print("上传成功") else: print(f"上传失败: {resp.status_code} - {resp.text}") except Exception as e: print(f"请求异常: {e}") msg_data = html_to_db(file.read_text(encoding='utf-8')) msg_data1 = msg_data.copy() msg_data1["messages"] = msg_data["messages"][:10] upload_msg(msg_data1, account="t-2217567810350-0", create_chat_id="3469772970637.PNM") msg_data2 = msg_data.copy() msg_data2["messages"] = msg_data["messages"][5:] upload_msg(msg_data2, account="t-2217567810350-0")
In [ ]:
import os from http import HTTPStatus from dashscope import Application response = Application.call( # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。 api_key="sk-17d17a164fb44ff99d88647bc6a1d551", app_id='83af9a2c0cf444da9a1860c91a1963ec',# 替换为实际的应用 ID prompt='你是谁?') if response.status_code != HTTPStatus.OK: print(f'request_id={response.request_id}') print(f'code={response.status_code}') print(f'message={response.message}') print(f'请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code') else: print(response.output.text)
In [ ]:
import os from http import HTTPStatus from dashscope import Application mdm = MySQLconnect("mdm") sql = """SELECT * FROM `tw_session_detail` WHERE session_id = 111""" chatdf = pd.read_sql(sql, mdm.engine()) rows_as_dict_list = chatdf.to_dict(orient='records') rows_as_dict_list
In [ ]:
import os from http import HTTPStatus from dashscope import Application response = Application.call( # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。 api_key="sk-17d17a164fb44ff99d88647bc6a1d551", app_id='83af9a2c0cf444da9a1860c91a1963ec',# 替换为实际的应用 ID prompt=str(rows_as_dict_list)) if response.status_code != HTTPStatus.OK: print(f'request_id={response.request_id}') print(f'code={response.status_code}') print(f'message={response.message}') print(f'请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code') else: print(json.loads(response.output.text)) #上传数据库 #
In [ ]:
################################################################## 上传聊天记录
In [ ]:
In [1]:
import os import pandas as pd from datetime import datetime from http import HTTPStatus from dashscope import Application from utils.gtools import MySQLconnect import json mdm = MySQLconnect('mdm') import requests
In [2]:
def upload_to_cpmaso(id,date,file,process_remark='',is_return=0,is_refund=0,is_find_goods=0): url = "http://192.168.100.44/rpaapi/upload_system_appointed_time" data = {"id":id,"date":date,"content":file,"process_remark":process_remark,"is_refund":is_refund,"is_return":is_return,"is_find_goods":is_find_goods} # id是任务idcontent是txt文件内容,remark是备注 headers = {"Content-Type": "application/json"} response = requests.post(url=url,json=data,headers=headers) return response
In [3]:
import os from http import HTTPStatus from dashscope import Application def aliyun(prompt): response = Application.call( # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。 api_key="sk-17d17a164fb44ff99d88647bc6a1d551", app_id='83af9a2c0cf444da9a1860c91a1963ec',# 替换为实际的应用 ID prompt=prompt) api_data = json.loads(response.output.text) return api_data
In [15]:
sql = """SELECT * FROM `tw_order_follow_up` where platform = '淘天' AND upload_cpmaso = 0"""
In [16]:
df = pd.read_sql(sql,mdm.engine()) df
Out[16]:
| cpmaso_task_id | buy_id | trade_id | trade_platform_order_num | pay_date | maintain_date | last_task_id | follow_type | max_logis_date | agreed_delivery_time | trans_id | payment_datetime | platform | task_status | need_refund | has_image | clearly_specify_the_delivery_time | one_more_time | create_date | upload_cpmaso | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 343636 | 2896029 | 2896029 | 2896029 | 2025-05-20 | 0 | 0 | 1 | 2025-05-21 | None | 1863624 | 1 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-21 | 0 |
| 1 | 343650 | 2896044 | 2896044 | 2896044 | 2025-05-20 | 0 | 0 | 1 | 2025-05-27 | None | 1863645 | 7 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-21 | 0 |
| 2 | 345441 | 2896633 | 2896633 | 2896633 | 2025-05-21 | 0 | 0 | 1 | 2025-05-22 | None | 1864349 | 1 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-22 | 0 |
| 3 | 345460 | 2896653 | 896653 | 896653 | 2025-05-21 | 0 | 0 | 1 | 2025-05-22 | None | 1864373 | 1 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-22 | 0 |
| 4 | 345510 | 2896706 | 2896706 | 2896706 | 2025-05-21 | 0 | 0 | 1 | 2025-05-23 | None | 1864440 | 2 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-22 | 0 |
| 5 | 347335 | 2897332 | 2897332 | 2897332 | 2025-05-22 | 0 | 0 | 1 | 2025-05-25 | None | 1865297 | 3 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-23 | 0 |
| 6 | 347339 | 2897336 | 2897336 | 2897336 | 2025-05-22 | 0 | 0 | 1 | 2025-05-27 | None | 1865301 | 5 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-23 | 0 |
| 7 | 347345 | 2897342 | 2897342 | 2897342 | 2025-05-22 | 0 | 0 | 1 | 2025-05-25 | None | 1865307 | 3 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-23 | 0 |
| 8 | 347348 | 2897345 | 2897345 | 2897345 | 2025-05-22 | 0 | 0 | 1 | 2025-05-24 | None | 1865308 | 2 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-23 | 0 |
| 9 | 347415 | 2897416 | 2897416 | 2897416 | 2025-05-22 | 0 | 0 | 1 | 2025-05-27 | None | 1865406 | 5 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-23 | 0 |
| 10 | 349155 | 2898014 | 2578499365301538788 | 1747991280236 | 2025-05-23 | 7 | 532 | 1 | 2025-05-30 | None | 1866518 | 7 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-24 | 0 |
| 11 | 349191 | 2898060 | 2577712694448538788 | 501566-186639528980603464 | 2025-05-23 | 3 | 533 | 1 | 2025-05-28 | None | 1866395 | 5 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-24 | 0 |
| 12 | 349219 | 2898090 | 2898090 | 2898090 | 2025-05-23 | 0 | 0 | 1 | 2025-05-30 | None | 1866272 | 7 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-24 | 0 |
| 13 | 349350 | 2898239 | 2898239 | 2898239 | 2025-05-23 | 0 | 0 | 1 | 2025-05-28 | None | 1866500 | 5 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-24 | 0 |
| 14 | 352340 | 2899178 | 2579933964195538788 | 501566-186750228991783425 | 2025-05-25 | 0 | 537 | 1 | 2025-05-30 | None | 1867502 | 5 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-26 | 0 |
| 15 | 352363 | 2899201 | 4354718580547688148 | 1748139827823 | 2025-05-25 | 5 | 540 | 1 | 2025-05-30 | None | 1867773 | 3 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-26 | 0 |
| 16 | 352392 | 2899231 | 2580629125407538788 | 501566-186754728992314910 | 2025-05-25 | 0 | 542 | 1 | 2025-05-30 | None | 1867547 | 5 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-26 | 0 |
| 17 | 352494 | 2899334 | 2579651619722538788 | 501566-186769728993341037 | 2025-05-25 | 0 | 553 | 1 | 2025-05-30 | None | 1867697 | 5 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-26 | 0 |
| 18 | 352504 | 2899345 | 2580008664490538788 | 501566-186771428993459718 | 2025-05-25 | 0 | 555 | 1 | 2025-05-30 | None | 1867714 | 5 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-26 | 0 |
| 19 | 352526 | 2899368 | 2579710119285538788 | 501566-186775328993689331 | 2025-05-25 | 0 | 558 | 1 | 2025-05-30 | None | 1867753 | 5 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-26 | 0 |
| 20 | 352631 | 2899481 | 2579924751782538788 | 501566-186789228994817432 | 2025-05-25 | 0 | 580 | 1 | 2025-05-30 | None | 1867892 | 5 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-26 | 0 |
| 21 | 352649 | 2899501 | 2899501 | 2899501 | 2025-05-25 | 0 | 0 | 1 | 2025-05-28 | None | 1867913 | 3 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-26 | 0 |
| 22 | 352698 | 2899552 | 4355089779147463948 | 1748152477497 | 2025-05-25 | 5 | 594 | 1 | 2025-05-30 | None | 1867983 | 5 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-26 | 0 |
| 23 | 352735 | 2899590 | 2580755954053538788 | 501566-186804028995900068 | 2025-05-25 | 0 | 601 | 1 | 2025-05-30 | None | 1868040 | 5 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-26 | 0 |
| 24 | 352741 | 2899596 | 2580765530729538788 | 501566-186804828995968241 | 2025-05-25 | 5 | 603 | 1 | 2025-05-30 | None | 1868048 | 5 | 淘天 | 0 | 0 | 0 | 0 | 0 | 2025-05-26 | 0 |
In [17]:
def update_follow_up(task_id,time='null',task_status=0,refund=0,has_image=1,clearly_time='0',one_more_time=0): sql = f""" UPDATE `tw_order_follow_up` SET agreed_delivery_time = {time},task_status = {task_status},need_refund = {refund}, has_image = {has_image},clearly_specify_the_delivery_time = {clearly_time},one_more_time = {one_more_time} WHERE cpmaso_task_id = "{task_id}" """ connect = mdm.connect() connect.cursor().execute(sql) connect.commit()
In [18]:
from datetime import datetime #id,date,file,remake='',is_return=0,is_refund=0,is_find_goods=0): for idx,row in df.iterrows(): #如果已发货,就上传记录 if row["task_status"] == 5: resp=upload_to_cpmaso(id=row["cpmaso_task_id"], date = datetime.now().strftime("%Y-%m-%d"), file = "", process_remark = "已发货") print(resp) url = 'http://192.168.100.44/rpaapi/upload_followup' data = { "task_id" : row["cpmaso_task_id"], "task_status":row["task_status"], "upload_cpmaso" : 1 } headers = {"Content-Type": "application/json"} response = requests.post(url=url,json=data,headers=headers) print(1) elif row["task_status"] == 0: chat_sql = f"""SELECT t3.* FROM `tw_order_follow_up` t1 LEFT JOIN tw_auto_task t2 on t1.last_task_id = t2.id LEFT JOIN tw_session_detail t3 on t3.session_id = t2.send_session WHERE cpmaso_task_id = {row["cpmaso_task_id"]} """ chatdf = pd.read_sql(chat_sql, mdm.engine()) if len(chatdf) == 0 or chatdf["id"][0] is None: continue else: last_match_idx = chatdf[chatdf['chat_content'].str.contains('平台交易号', na=False)].index[-1] # # 获取该行及之后所有行 chatdf = chatdf.loc[last_match_idx:] if len(chatdf) == 1: resp=upload_to_cpmaso(id=row["cpmaso_task_id"], date ="", file = str(chatdf.to_dict(orient='records')), process_remark = "买家未回复") continue elif len(chatdf) >= 2: pass rows_as_dict_list = chatdf.to_dict(orient='records') prompt=str(rows_as_dict_list) chat_list = [row['chat_content'] for row in rows_as_dict_list] api_data= aliyun(prompt) print(chat_list) deliver_date = api_data['result']['约定发货信息']['发货时间'] #发货时间 answer_result = api_data["result"]['回复结果'] # 回复结果 is_return = api_data['result']['是否需要退款'] is_deliver = api_data['result']['是否已发货'] is_ask = api_data['result']['是否需要追问'] time = datetime.strptime(deliver_date, "%Y/%m/%d").date().strftime("%Y-%m-%d") if deliver_date else "" need_refund = 1 if is_return == "是" else 0 clearly_time = 1 if answer_result == '明确发货时间' else 2 if answer_result == '无法明确发货时间' else 3 one_more_time = 1 if is_ask == '是' else 2 has_image = 1 if answer_result == '内含图片' else 0 task_status = 5 if answer_result == '回复已发货' else 4 if has_image == 1 else 1 if clearly_time == 2 else 2 if clearly_time == 1 else 1 task_status = 4 if need_refund == 1 else task_status print(api_data) resp=upload_to_cpmaso(id=row["cpmaso_task_id"], date = time, file = str(chatdf.to_dict(orient='records')), process_remark = answer_result) url = 'http://192.168.100.44/rpaapi/upload_followup' data = { "task_id" : row["cpmaso_task_id"], "time":time, "task_status":task_status, "refund": need_refund, "has_image":has_image, "clearly_time":clearly_time, "one_more_time":one_more_time, "upload_cpmaso" : 1 } headers = {"Content-Type": "application/json"} response = requests.post(url=url,json=data,headers=headers) print(1) for j in range(len(rows_as_dict_list)): id = rows_as_dict_list[j]['id'] url = 'http://192.168.100.44/rpaapi/read' data = {"chat_id":id} headers = {"Content-Type": "application/json"} requests.post(url=url,json=data,headers=headers)
In [ ]:
def aliyun(rows_as_dict_list): response = Application.call( # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。 api_key="sk-17d17a164fb44ff99d88647bc6a1d551", app_id='83af9a2c0cf444da9a1860c91a1963ec',# 替换为实际的应用 ID prompt=str(rows_as_dict_list)) api_data = json.loads(response.output.text) return api_data deliver_date = api_data['result']['约定发货信息']['发货时间'] #发货时间 answer_result = api_data["result"]['回复结果'] # 回复结果 is_return = api_data['result']['是否需要退款'] is_deliver = api_data['result']['是否已发货'] is_ask = api_data['result']['是否需要追问'] time = datetime.strptime(deliver_date, "%Y/%m/%d").date() if deliver_date else None need_refund = 1 if is_return == "是" else 0 clearly_time = 1 if answer_result == '明确发货时间' else 2 if answer_result == '无法明确发货时间' else 3 one_more_time = 1 if is_ask == '是' else 2 has_image = 1 if answer_result == '内含图片' else 0 task_status = 5 if answer_result == '回复已发货' else 4 if has_image == 1 else 1 if clearly_time == 2 else 2 if clearly_time == 1 else 1 task_status = 4 if need_refund == 1 else task_status print(api_data) url = 'http://192.168.100.44/rpaapi/upload_followup' data = { "task_id" : df.iloc[i,1],"time":time, "task_status":task_status, "refund": need_refund, "has_image":has_image, "clearly_time":clearly_time, "one_more_time":one_more_time } headers = {"Content-Type": "application/json"} response = requests.post(url=url,json=data,headers=headers) print(1)
In [ ]:
In [ ]:
############################################################# 聊天记录上传系统
In [ ]:
sql = """SELECT cpmaso_task_id,agreed_delivery_time,task_status,need_refund,clearly_specify_the_delivery_time,one_more_time from tw_order_follow_up where platform = '淘天' and DATE(create_date) = DATE(CONVERT_TZ(NOW(), '+00:00', '+08:00')) and task_status != 0 and task_status != 5 and task_status != 4""" df = pd.read_sql(sql,mdm.engine())
In [ ]:
def upload_to_cpmaso(id,date,file,remake='',is_return=0,is_refund=0,is_find_goods=0): url = "http://192.168.100.44/rpaapi/upload_system_appointed_time" data = {"id":id,"date":date,"content":file,"remark":remake,"is_refund":is_refund,"is_return":is_return,"is_find_goods":is_find_goods} # id是任务idcontent是txt文件内容,remark是备注 headers = {"Content-Type": "application/json"} response = requests.post(url=url,json=data,headers=headers) print(response)
In [ ]:
for i in range(len(df)): type_id = str(df.iloc[i]['cpmaso_task_id']) is_refund = str(df.iloc[i]['need_refund']) if df.iloc[i]['agreed_delivery_time']: # 如果时间不为空 date = str(df.iloc[i]['agreed_delivery_time']) remake= '' else: date = '' remake = '没有明确时间' msg_sql = f"""SELECT b.* FROM tw_auto_task a left join tw_session_detail b on a.send_session = b.session_id where a.type_id = {type_id}""" msg_df = pd.read_sql(msg_sql,mdm.engine()) msg_df['chat_date'] = msg_df['chat_date'].dt.strftime('%Y-%m-%d %H:%M:%S') msg_file = msg_df.to_dict(orient='records') upload_to_cpmaso(id=type_id,date=date,file=msg_file,is_refund=is_refund,remake=remake) print(msg_file)
In [ ]: