logistics/自动化跟单.ipynb

202 lines
6.4 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd \n",
"import requests \n",
"from login_for_cookie import Vc\n",
"import pendulum\n",
"import json\n",
"from utils.gtools import MySQLconnect \n",
"from lxml import etree\n",
"from pathlib import Path\n",
"from datetime import datetime\n",
"cookie = Vc()\n",
"headers = {\"Cookie\":cookie}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def get_fs(row):\n",
" data = row[\"采购单号\"]\n",
" buy_url = \"http://cp.maso.hk/index.php?main=store_in_receive\"\n",
"\n",
" payload = {\n",
" \"s_pid\": 2867159,\n",
" \"s_suborderid\": \"\",\n",
" \"pdt_standard_id\": \"\",\n",
" \"s_store\": -1,\n",
" \"s_status[0]\": 0,\n",
" \"s_sort\": \"desc\",\n",
" \"Submit\": \"查询\",\n",
" \"synergy_sign\": -1,\n",
" \"start_dep\": \"\",\n",
" \"start_user\": \"\",\n",
" \"to_dep\": \"\",\n",
" \"to_user\": \"\",\n",
" \"swebid\": 0,\n",
" \"local_pdt_id\": 0,\n",
" \"sadd_time\": \"\",\n",
" \"sadd_time_end\": \"\",\n",
" \"sreal_express_no\": \"\",\n",
" \"sweb_id\": \"\",\n",
" \"sof\": 0,\n",
" \"soe\": 0,\n",
" \"sod\": \"\",\n",
" \"tsid\": -1,\n",
" \"tsdid\": -1,\n",
" \"tsst\": -1,\n",
" \"order_cate\": -1,\n",
" \"error_status\": -1,\n",
" \"web_uid\": -1,\n",
" \"team_id\": -1,\n",
" \"handle\": -1,\n",
" \"handle_uid\": 0,\n",
" \"handle_time_start\": \"\",\n",
" \"handle_time_end\": \"\",\n",
" \"shiping_time_start\": \"\",\n",
" \"shiping_time_end\": \"\",\n",
" \"trade_time_start\": \"\",\n",
" \"trade_time_end\": \"\",\n",
" \"order_express_fee\": -1,\n",
" \"web_type\": -1,\n",
" \"shipping_type\": -1,\n",
" \"maintain_add_time_s\": \"\",\n",
" \"maintain_add_time_e\": \"\",\n",
" \"maintain_comfirm_time_s\": \"\",\n",
" \"maintain_comfirm_time_e\": \"\",\n",
" \"dispense_user_id\": \"\",\n",
" \"export_page\": 1\n",
" }\n",
" payload[\"s_pid\"] = data\n",
" resp = requests.post(url = buy_url ,headers=headers , data=payload)\n",
" buy_df_list = pd.read_html(resp.text,match=\"所属网站ID\")\n",
" buy_df = buy_df_list[1]\n",
" buy_df.columns = buy_df.loc[0,:]\n",
" trade_id = buy_df[\"交易ID\"][1]\n",
" #交易明细里头\n",
" trade_url = f\"http://cp.maso.hk/index.php?main=store_tradelist_info&trade_id={trade_id}\"\n",
" resp2 = requests.get(url = trade_url ,headers=headers )\n",
" df_list2 = pd.read_html(resp2.text,match=\"下单发货时间\")\n",
" df2 = df_list2[0]\n",
" df2.columns = df2.loc[0,:]\n",
" 下单发货时间 = int(df2.iloc[2,1][0].replace(\"--\",\"0\"))\n",
" 维护发货时间 = int(df2.iloc[2,3].replace(\"--\",\"0\"))\n",
" 支付时间 = pendulum.parse(df2.iloc[3,3])\n",
" 最大发货时间 = 支付时间.add(days=max(下单发货时间,维护发货时间))\n",
" #交易列表\n",
" trade_list_url = f\"http://cp.maso.hk/index.php?main=store_in_receive&navlist=trade_list&s_trade_id={trade_id}\"\n",
" resp3 = requests.get(url = trade_list_url ,headers=headers )\n",
" df_list3 = pd.read_html(resp3.text,match=\"涨幅\")\n",
" df3 = df_list3[0]\n",
" df3.columns = df3.loc[0,:]\n",
" 交易平台 = df3[\"交易平台\"][1]\n",
" 交易号 = df3[\"交易号\"][1]\n",
" 交易平台订单号 = df3[\"交易平台订单号\"][1]\n",
" \n",
" return pd.Series([trade_id,下单发货时间, 维护发货时间,支付时间,最大发货时间,交易平台,交易号,交易平台订单号])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"url = f\"https://cp.maso.hk/index.php?main=orderlist_info&id={order_id}\"\n",
"resp = requests.get(url = url ,headers=headers)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd \n",
"df_list = pd.read_html(resp.text,match=\"基础估算\")\n",
"goaldf = df_list[1]\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_excel(r\"F:\\DOCUMENTS\\WXWork\\1688854527635889\\Cache\\File\\2025-05\\新建Microsoft Excel 工作表 (2)(1).xlsx\",sheet_name=\"Sheet5\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd \n",
"\n",
"def a(order_id,package):\n",
" url = f\"https://cp.maso.hk/index.php?main=orderlist_info&id={order_id}\"\n",
" resp = requests.get(url = url ,headers=headers)\n",
" df_list = pd.read_html(resp.text,match=\"基础估算\")\n",
" goaldf = df_list[1]\n",
" for idx,value in goaldf[1].items():\n",
" if str(package) == str(value):\n",
" fees = goaldf[5][idx+1]\n",
" fee_list= fees.split(' ')\n",
" fee1 = fee_list[1]\n",
" fee2 = fee_list[2]\n",
" print(fees)\n",
" fee = (float(fee1.replace(',','')) + float(fee2.replace(',','')))/7\n",
" print(fee1,fee2,fee)\n",
" return round(fee,2)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for index,row in df.iterrows():\n",
" if row['快递公司'] ==\"海MS-WWEX-SAIR\":\n",
" df.at[index,'尾端'] = a(row[\"order_id\"],row[\"包裹号\"])\n",
" else:\n",
" continue\n",
"df.to_clipboard(index=False)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}