157 lines
6.5 KiB
Plaintext
157 lines
6.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"id": "initial_id",
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"ExecuteTime": {
|
|
"end_time": "2024-11-22T08:49:41.787341Z",
|
|
"start_time": "2024-11-22T08:09:20.489931Z"
|
|
}
|
|
},
|
|
"source": [
|
|
"import requests\n",
|
|
"import pandas as pd\n",
|
|
"from tqdm import tqdm\n",
|
|
"import time\n",
|
|
"# 历史维修记录明细\n",
|
|
"# 请求过于频繁会挂掉\n",
|
|
"\n",
|
|
"url = 'https://erp.byjy168.cn/top/statistics/fix/worksheetHistory/summary/new'\n",
|
|
"\n",
|
|
"headers = {\n",
|
|
" 'Accept': '*/*',\n",
|
|
" 'Accept-Encoding': 'gzip, deflate, br, zstd',\n",
|
|
" 'Accept-Language': 'zh-CN,zh;q=0.9',\n",
|
|
" 'Connection': 'keep-alive',\n",
|
|
" 'Cookie': 'JSESSIONID=D0A01E7B7FA40CB76F1770BF36556A66',\n",
|
|
" 'Host': 'erp.byjy168.cn',\n",
|
|
" 'Referer': 'https://erp.byjy168.cn/dashboard/index/reportforms/history',\n",
|
|
" 'Sec-Ch-Ua': '\"Microsoft Edge\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"',\n",
|
|
" 'Sec-Ch-Ua-Mobile': '?0',\n",
|
|
" 'Sec-Ch-Ua-Platform': '\"Windows\"',\n",
|
|
" 'Sec-Fetch-Dest': 'empty',\n",
|
|
" 'Sec-Fetch-Mode': 'cors',\n",
|
|
" 'Sec-Fetch-Site': 'same-origin',\n",
|
|
" 'Token':'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIzMDMxNyIsInVzZXJuYW1lIjoi5p2O54KcIiwibmFtZSI6IiIsImNvbXBhbnlJZCI6NDIzOSwib3BlcmF0b3JJZCI6MywicGhvbmUiOiIxODY4ODU1MjI3OCIsIm1lbnVUeXBlIjoiMSIsImNvbW5vIjoiQTAxIiwicGNvcmFwcCI6InBjIiwiZXhwIjoxNzMyNjk0NTkyfQ.EgVtyoVcOWZ4EmdYHv52k6Cruk8FExTF4Gp-u_4Ug3I',\n",
|
|
" 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0'\n",
|
|
"}\n",
|
|
"\n",
|
|
"all_data_list = []\n",
|
|
"for i in tqdm(range(1, 655), desc='Processing pages', unit='page'):\n",
|
|
" time.sleep(2)\n",
|
|
" data = f'current={i}&size=10&status=&gridCode=GS011340&isOtherAccess=1&comno=A01&shopCode=A01'\n",
|
|
"\n",
|
|
" response = requests.post(url=url, headers=headers, data=data)\n",
|
|
"\n",
|
|
" if response.status_code == 200:\n",
|
|
" data = response.json()\n",
|
|
" data_list = data['data']['records']\n",
|
|
"\n",
|
|
" for data in data_list:\n",
|
|
" work_sheet_code = data['worksheetCode']\n",
|
|
" all_data_list.append(data)\n",
|
|
" url1 = f'https://erp.byjy168.cn/api/repairServiceHistory/getListByCode?worksheetCode={work_sheet_code}&shopCode=A01'\n",
|
|
" res = requests.get(url=url1, headers=headers)\n",
|
|
" if res.status_code == 200:\n",
|
|
" data1 = res.json()\n",
|
|
" details = []\n",
|
|
" for detail in data1['data']:\n",
|
|
" all_data_list.append(detail)\n",
|
|
" time.sleep(1)\n",
|
|
" else:\n",
|
|
" print(f\"Failed to get details for worksheetCode {work_sheet_code}, status code: {res.status_code}\")\n",
|
|
" else:\n",
|
|
" print(f\"Failed to retrieve page {i}, status code: {response.status_code}\")\n",
|
|
" \n",
|
|
"df = pd.DataFrame(all_data_list)\n",
|
|
"# 定义新列名\n",
|
|
"new_columns = {\n",
|
|
" 'inDate': '收银时间',\n",
|
|
" 'customerName': '客户名称',\n",
|
|
" 'registerNo': '车牌号',\n",
|
|
" 'model': '车型',\n",
|
|
" 'status': '状态',\n",
|
|
" 'receptionSource': '客户来源',\n",
|
|
" 'serviceType': '业务类型',\n",
|
|
" 'relasalesName': '客户经理',\n",
|
|
" 'recpersonName': '接待人',\n",
|
|
" 'mainworkerName': '维修技师',\n",
|
|
" 'recmoneyDate': '收银时间',\n",
|
|
" 'timeAmount': '工时金额',\n",
|
|
" 'partAmount': '配件金额',\n",
|
|
" 'addAmount': '增值金额',\n",
|
|
" 'amount': '合计金额',\n",
|
|
" 'otherAmount': '其他金额',\n",
|
|
" 'discountAmount': '减收金额',\n",
|
|
" 'totalAmount': '实收金额',\n",
|
|
" 'costAmount': '实收成本',\n",
|
|
" 'cashAmount': '现金',\n",
|
|
" 'arrearAmount': '挂帐金额',\n",
|
|
" 'cardAmount': '刷卡',\n",
|
|
" 'wxAmount': '微信支付',\n",
|
|
" 'zfbAmount': '支付宝支付',\n",
|
|
" 'accotherdetail': '其它支付明细',\n",
|
|
" 'balanceAmount': '欠款余额',\n",
|
|
" 'serviceCode': '项目编码',\n",
|
|
" 'serviceName': '项目名称',\n",
|
|
" 'workTime': '工时',\n",
|
|
" 'timePrice': '项目单价',\n",
|
|
" 'mainWorkerName': '主修员',\n",
|
|
" # 继续添加更多的列名映射...\n",
|
|
"}\n",
|
|
"# 使用rename方法替换列名\n",
|
|
"df.rename(columns=new_columns, inplace=True)\n",
|
|
"# 保存到Excel文件\n",
|
|
"file_path = r'D:\\Idea Project\\F6+宜搭+其它(1)\\new\\文件输出\\百少侠导出数据.xlsx'\n",
|
|
"df.to_excel(file_path, index=False)\n",
|
|
"\n",
|
|
"print(f\"数据已成功保存至{file_path}\") \n"
|
|
],
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Processing pages: 43%|████▎ | 282/654 [40:21<53:13, 8.59s/page] \n"
|
|
]
|
|
},
|
|
{
|
|
"ename": "KeyError",
|
|
"evalue": "'data'",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
|
|
"\u001B[1;31mKeyError\u001B[0m Traceback (most recent call last)",
|
|
"Cell \u001B[1;32mIn[17], line 45\u001B[0m\n\u001B[0;32m 43\u001B[0m data1 \u001B[38;5;241m=\u001B[39m res\u001B[38;5;241m.\u001B[39mjson()\n\u001B[0;32m 44\u001B[0m details \u001B[38;5;241m=\u001B[39m []\n\u001B[1;32m---> 45\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m detail \u001B[38;5;129;01min\u001B[39;00m data1[\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mdata\u001B[39m\u001B[38;5;124m'\u001B[39m]:\n\u001B[0;32m 46\u001B[0m all_data_list\u001B[38;5;241m.\u001B[39mappend(detail)\n\u001B[0;32m 47\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n",
|
|
"\u001B[1;31mKeyError\u001B[0m: 'data'"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 17
|
|
}
|
|
],
|
|
"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
|
|
}
|