Files
F6--/张阳脚本/竞品系统数据导出/米其林驰加系统导出.ipynb
T
2026-01-30 11:28:35 +08:00

378 lines
16 KiB
Plaintext

{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "# 车辆信息导出",
"id": "a738ca16021a9e3b"
},
{
"cell_type": "code",
"id": "initial_id",
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2025-12-22T09:33:52.535439Z",
"start_time": "2025-12-22T09:24:33.820278Z"
}
},
"source": [
"import time\n",
"\n",
"import pandas as pd\n",
"import requests\n",
"from tqdm import tqdm\n",
"\n",
"cookies = {\n",
" 'acw_tc': '0a472f4517663729846515826e48e5fe00deb9589551f37ca83749c9ce043f',\n",
" 'Hm_lvt_684c22b31d0037eca5a691cde16370ad': '1765863565,1766372987',\n",
" 'Hm_lpvt_684c22b31d0037eca5a691cde16370ad': '1766372987',\n",
" 'HMACCOUNT': '55F2182717FD6AE6',\n",
" 'e_token': 'd6c91f1dbb754081948988a722287335',\n",
" 'weixin_token': 'Y',\n",
" 'e_c': 'MzY3NTI1OTM0OTg4NzQxMA==',\n",
" 'e_i_o_c_n': 'JTIyJUU5JUE5JUIwJUU1JThBJUEwJUU2JUIxJUJEJUU4JUJEJUE2JUU2JTlDJThEJUU1JThBJUExJUU0JUI4JUFEJUU1JUJGJTgzJUU5JUJDJThFJUU2JUI5JTk2JUU1JThDJUJBJUU1JTlEJTkxJUU1JThGJUEzJUU1JUJBJTk3JTVCKzIwMDI3NDUrJTVEJTIy',\n",
" 'e_i_p_c_n': 'JTIyJUU5JUE5JUIwJUU1JThBJUEwJUU2JUIxJUJEJUU4JUJEJUE2JUU2JTlDJThEJUU1JThBJUExJUU0JUI4JUFEJUU1JUJGJTgzJUU5JUJDJThFJUU2JUI5JTk2JUU1JThDJUJBJUU1JTlEJTkxJUU1JThGJUEzJUU1JUJBJTk3JUU1JUJBJTk3JUU0JUI4JUJCJTVCKzIwMjk4NjkrJTVEJTIy',\n",
"}\n",
"\n",
"headers = {\n",
" 'Accept': 'application/json, text/plain, */*',\n",
" 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',\n",
" 'Cache-Control': 'no-cache',\n",
" 'Connection': 'keep-alive',\n",
" 'Content-Type': 'application/json;charset=UTF-8',\n",
" 'Irisclient': 'PC-web#tedspc',\n",
" 'Origin': 'https://teds.tyreplus.com.cn',\n",
" 'Pragma': 'no-cache',\n",
" 'Referer': 'https://teds.tyreplus.com.cn/tedspc/index.html',\n",
" 'Sec-Fetch-Dest': 'empty',\n",
" 'Sec-Fetch-Mode': 'cors',\n",
" 'Sec-Fetch-Site': 'same-origin',\n",
" 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0',\n",
" 'sec-ch-ua': '\"Microsoft Edge\";v=\"143\", \"Chromium\";v=\"143\", \"Not A(Brand\";v=\"24\"',\n",
" 'sec-ch-ua-mobile': '?0',\n",
" 'sec-ch-ua-platform': '\"Windows\"',\n",
"}\n",
"\n",
"all_data = []\n",
"for i in tqdm(range(1, 1144)):\n",
" json_data = {\n",
" 'pageStart': i,\n",
" 'pageNums': 10,\n",
" 'pageNum': 1,\n",
" 'pageSize': 10,\n",
" }\n",
"\n",
" response = requests.post(\n",
" 'https://teds.tyreplus.com.cn/api/v1/custom/vehicle/queryVehicleInfosByStore',\n",
" cookies=cookies,\n",
" headers=headers,\n",
" json=json_data,\n",
" )\n",
" data_list = response.json()['obj']['list']\n",
" all_data += data_list\n",
"\n",
"df = pd.DataFrame(all_data)\n",
"df.to_excel(r\"D:\\Idea Project\\F6+宜搭+其它(1)\\张阳脚本\\文件输出\\驰加车辆信息.xlsx\", index=False)\n",
"\n"
],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1143/1143 [08:56<00:00, 2.13it/s]\n"
]
}
],
"execution_count": 4
},
{
"metadata": {},
"cell_type": "markdown",
"source": "# 历史维修记录列表(结算单)",
"id": "e166fa181fddc651"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-22T03:17:34.270096Z",
"start_time": "2025-12-22T03:12:30.351185Z"
}
},
"cell_type": "code",
"source": [
"import requests\n",
"from tqdm import tqdm\n",
"import pandas as pd\n",
"\n",
"cookies = {\n",
" 'acw_tc': '0a472f4517663729846515826e48e5fe00deb9589551f37ca83749c9ce043f',\n",
" 'Hm_lvt_684c22b31d0037eca5a691cde16370ad': '1765863565,1766372987',\n",
" 'Hm_lpvt_684c22b31d0037eca5a691cde16370ad': '1766372987',\n",
" 'HMACCOUNT': '55F2182717FD6AE6',\n",
" 'e_token': 'd6c91f1dbb754081948988a722287335',\n",
" 'weixin_token': 'Y',\n",
" 'e_c': 'MzY3NTI1OTM0OTg4NzQxMA==',\n",
" 'e_i_o_c_n': 'JTIyJUU5JUE5JUIwJUU1JThBJUEwJUU2JUIxJUJEJUU4JUJEJUE2JUU2JTlDJThEJUU1JThBJUExJUU0JUI4JUFEJUU1JUJGJTgzJUU5JUJDJThFJUU2JUI5JTk2JUU1JThDJUJBJUU1JTlEJTkxJUU1JThGJUEzJUU1JUJBJTk3JTVCKzIwMDI3NDUrJTVEJTIy',\n",
" 'e_i_p_c_n': 'JTIyJUU5JUE5JUIwJUU1JThBJUEwJUU2JUIxJUJEJUU4JUJEJUE2JUU2JTlDJThEJUU1JThBJUExJUU0JUI4JUFEJUU1JUJGJTgzJUU5JUJDJThFJUU2JUI5JTk2JUU1JThDJUJBJUU1JTlEJTkxJUU1JThGJUEzJUU1JUJBJTk3JUU1JUJBJTk3JUU0JUI4JUJCJTVCKzIwMjk4NjkrJTVEJTIy',\n",
"}\n",
"\n",
"headers = {\n",
" 'Accept': 'application/json, text/plain, */*',\n",
" 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',\n",
" 'Cache-Control': 'no-cache',\n",
" 'Connection': 'keep-alive',\n",
" 'Content-Type': 'application/json;charset=UTF-8',\n",
" 'Irisclient': 'PC-web#tedspc',\n",
" 'Origin': 'https://teds.tyreplus.com.cn',\n",
" 'Pragma': 'no-cache',\n",
" 'Referer': 'https://teds.tyreplus.com.cn/tedspc/index.html',\n",
" 'Sec-Fetch-Dest': 'empty',\n",
" 'Sec-Fetch-Mode': 'cors',\n",
" 'Sec-Fetch-Site': 'same-origin',\n",
" 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0',\n",
" 'sec-ch-ua': '\"Microsoft Edge\";v=\"143\", \"Chromium\";v=\"143\", \"Not A(Brand\";v=\"24\"',\n",
" 'sec-ch-ua-mobile': '?0',\n",
" 'sec-ch-ua-platform': '\"Windows\"',\n",
"}\n",
"\n",
"history_all_data = []\n",
"for i in tqdm(range(1, 848)):\n",
" json_data = {\n",
" # 记得修改门店list\n",
" 'storeCodeList': [\n",
" '302558',\n",
" '366900',\n",
" ],\n",
" 'pageStart': i,\n",
" 'pageNums': 10,\n",
" 'pageNum': i,\n",
" 'pageSize': 10,\n",
" }\n",
"\n",
" response = requests.post(\n",
" 'https://teds.tyreplus.com.cn/api/aftersales/payment/queryPaymentSettlementListByCondition',\n",
" cookies=cookies,\n",
" headers=headers,\n",
" json=json_data,\n",
" )\n",
" history_data_list = response.json()['obj']['list']\n",
" history_all_data += history_data_list\n",
"\n",
"df = pd.DataFrame(history_all_data)\n",
"df.to_excel(r\"D:\\Idea Project\\F6+宜搭+其它(1)\\张阳脚本\\文件输出\\结算单.xlsx\", index=False)\n"
],
"id": "51f8f4b21505280a",
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 847/847 [04:53<00:00, 2.89it/s]\n"
]
}
],
"execution_count": 2
},
{
"metadata": {},
"cell_type": "markdown",
"source": "历史维修记录明细(结算单明细)",
"id": "44cdf0d8f5f01c7d"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-22T09:16:59.210944Z",
"start_time": "2025-12-22T05:46:03.111327Z"
}
},
"cell_type": "code",
"source": [
"import requests\n",
"from tqdm.notebook import tqdm\n",
"import pandas as pd\n",
"import time\n",
"\n",
"cookies = {\n",
" 'acw_tc': '0a472f4517663729846515826e48e5fe00deb9589551f37ca83749c9ce043f',\n",
" 'Hm_lvt_684c22b31d0037eca5a691cde16370ad': '1765863565,1766372987',\n",
" 'Hm_lpvt_684c22b31d0037eca5a691cde16370ad': '1766372987',\n",
" 'HMACCOUNT': '55F2182717FD6AE6',\n",
" 'e_token': 'd6c91f1dbb754081948988a722287335',\n",
" 'weixin_token': 'Y',\n",
" 'e_c': 'MzY3NTI1OTM0OTg4NzQxMA==',\n",
" 'e_i_o_c_n': 'JTIyJUU5JUE5JUIwJUU1JThBJUEwJUU2JUIxJUJEJUU4JUJEJUE2JUU2JTlDJThEJUU1JThBJUExJUU0JUI4JUFEJUU1JUJGJTgzJUU5JUJDJThFJUU2JUI5JTk2JUU1JThDJUJBJUU1JTlEJTkxJUU1JThGJUEzJUU1JUJBJTk3JTVCKzIwMDI3NDUrJTVEJTIy',\n",
" 'e_i_p_c_n': 'JTIyJUU5JUE5JUIwJUU1JThBJUEwJUU2JUIxJUJEJUU4JUJEJUE2JUU2JTlDJThEJUU1JThBJUExJUU0JUI4JUFEJUU1JUJGJTgzJUU5JUJDJThFJUU2JUI5JTk2JUU1JThDJUJBJUU1JTlEJTkxJUU1JThGJUEzJUU1JUJBJTk3JUU1JUJBJTk3JUU0JUI4JUJCJTVCKzIwMjk4NjkrJTVEJTIy',\n",
"}\n",
"\n",
"headers = {\n",
" 'Accept': 'application/json, text/plain, */*',\n",
" 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',\n",
" 'Cache-Control': 'no-cache',\n",
" 'Connection': 'keep-alive',\n",
" 'Content-Type': 'application/json;charset=UTF-8',\n",
" 'Irisclient': 'PC-web#tedspc',\n",
" 'Origin': 'https://teds.tyreplus.com.cn',\n",
" 'Pragma': 'no-cache',\n",
" 'Referer': 'https://teds.tyreplus.com.cn/tedspc/index.html',\n",
" 'Sec-Fetch-Dest': 'empty',\n",
" 'Sec-Fetch-Mode': 'cors',\n",
" 'Sec-Fetch-Site': 'same-origin',\n",
" 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0',\n",
" 'sec-ch-ua': '\"Microsoft Edge\";v=\"143\", \"Chromium\";v=\"143\", \"Not A(Brand\";v=\"24\"',\n",
" 'sec-ch-ua-mobile': '?0',\n",
" 'sec-ch-ua-platform': '\"Windows\"',\n",
"}\n",
"\n",
"df = pd.read_excel(\"D:\\Idea Project\\F6+宜搭+其它(1)\\张阳脚本\\文件输出\\结算单.xlsx\", sheet_name='Sheet1')\n",
"\n",
"all_data_list = []\n",
"all_service_data = []\n",
"all_order_data = []\n",
"all_payment_data = []\n",
"\n",
"for index, row in tqdm(df.iterrows(), total=len(df)):\n",
" id = row[\"paymentNo\"]\n",
" json_data = {\n",
" 'paymentNo': id,\n",
" }\n",
"\n",
" retry_count = 0\n",
" success = False\n",
"\n",
" while retry_count < 5 and not success:\n",
" try:\n",
" response = requests.post(\n",
" 'https://teds.tyreplus.com.cn/api/v2/aftersales/payment/queryPaymentSettlementDetail',\n",
" cookies=cookies,\n",
" headers=headers,\n",
" json=json_data,\n",
" timeout=10 # 建议加上超时防止卡死\n",
" )\n",
"\n",
" # 检查响应状态码和返回内容是否有效\n",
" if response.status_code == 200:\n",
" resp_json = response.json()\n",
" if resp_json.get('code') == 'success' and 'obj' in resp_json:\n",
" all_data = resp_json['obj']\n",
" service_list = all_data.get('orderServiceList', [])\n",
" order_list = all_data.get('orderSkuList', [])\n",
" paymentMethodList = all_data.get('paymentMethodList', [])\n",
"\n",
" # 添加 paymentNo 字段\n",
" all_data['paymentNo'] = id\n",
" all_data_list.append(all_data)\n",
"\n",
" for service in service_list:\n",
" service['paymentNo'] = id\n",
" all_service_data.append(service)\n",
"\n",
" for order in order_list:\n",
" order['paymentNo'] = id\n",
" all_order_data.append(order)\n",
"\n",
" for payment in paymentMethodList:\n",
" payment['paymentNo'] = id\n",
" all_payment_data.append(payment)\n",
"\n",
" success = True # 成功获取数据,跳出重试循环\n",
" else:\n",
" print(f\"请求返回非成功状态: {resp_json.get('message', '未知错误')} (paymentNo: {id})\")\n",
" else:\n",
" print(f\"HTTP 请求失败,状态码: {response.status_code} (paymentNo: {id})\")\n",
"\n",
" except Exception as e:\n",
" print(f\"请求异常: {e} (paymentNo: {id})\")\n",
"\n",
" if not success:\n",
" retry_count += 1\n",
" if retry_count < 5:\n",
" time.sleep(2) # 等待 2 秒后重试\n",
" else:\n",
" print(f\"已达到最大重试次数,跳过 paymentNo: {id}\")\n",
"\n",
" time.sleep(1) # 正常请求之间仍保留 1 秒间隔\n",
"\n",
"# 创建DataFrame\n",
"df = pd.DataFrame(all_data_list)\n",
"df1 = pd.DataFrame(all_service_data)\n",
"df2 = pd.DataFrame(all_order_data)\n",
"df3 = pd.DataFrame(all_payment_data)\n",
"\n",
"# 保存到Excel\n",
"df.to_excel(r\"D:\\Idea Project\\F6+宜搭+其它(1)\\张阳脚本\\文件输出\\历史维修记录明细.xlsx\", index=False)\n",
"df1.to_excel(r\"D:\\Idea Project\\F6+宜搭+其它(1)\\张阳脚本\\文件输出\\历史维修记录明细-服务明细.xlsx\", index=False)\n",
"df2.to_excel(r\"D:\\Idea Project\\F6+宜搭+其它(1)\\张阳脚本\\文件输出\\历史维修记录明细-产品明细.xlsx\", index=False)\n",
"df3.to_excel(r\"D:\\Idea Project\\F6+宜搭+其它(1)\\张阳脚本\\文件输出\\历史维修记录明细-支付方式.xlsx\", index=False)\n"
],
"id": "b7e0d7a4da6c9b03",
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"<>:37: SyntaxWarning: invalid escape sequence '\\I'\n",
"<>:37: SyntaxWarning: invalid escape sequence '\\I'\n",
"C:\\Users\\zy187\\AppData\\Local\\Temp\\ipykernel_29896\\1397566597.py:37: SyntaxWarning: invalid escape sequence '\\I'\n",
" df = pd.read_excel(\"D:\\Idea Project\\F6+宜搭+其它(1)\\张阳脚本\\文件输出\\结算单.xlsx\", sheet_name='Sheet1')\n"
]
},
{
"data": {
"text/plain": [
" 0%| | 0/8463 [00:00<?, ?it/s]"
],
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "6e51c0e7de2f4a7aab44e2c939cba811"
}
},
"metadata": {},
"output_type": "display_data",
"jetTransient": {
"display_id": null
}
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"HTTP 请求失败,状态码: 504 (paymentNo: SI2512141629588397)\n",
"请求异常: HTTPSConnectionPool(host='teds.tyreplus.com.cn', port=443): Read timed out. (read timeout=10) (paymentNo: SI2509131018744247)\n",
"请求异常: HTTPSConnectionPool(host='teds.tyreplus.com.cn', port=443): Read timed out. (read timeout=10) (paymentNo: SI2508260841398950)\n",
"请求异常: HTTPSConnectionPool(host='teds.tyreplus.com.cn', port=443): Read timed out. (read timeout=10) (paymentNo: SI2508171023222117)\n",
"请求异常: HTTPSConnectionPool(host='teds.tyreplus.com.cn', port=443): Read timed out. (read timeout=10) (paymentNo: SI2508091817076414)\n",
"请求异常: HTTPSConnectionPool(host='teds.tyreplus.com.cn', port=443): Read timed out. (read timeout=10) (paymentNo: SI2508081059041103)\n",
"请求异常: HTTPSConnectionPool(host='teds.tyreplus.com.cn', port=443): Read timed out. (read timeout=10) (paymentNo: SI2508011823922622)\n"
]
}
],
"execution_count": 3
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}