代码拉取完成,页面将自动刷新
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
# @Project : pythonProject
# @File : kai_dan_ming_xi_mu_ban
# @Date : 2023/12/21 15:49
# @Author : 徐胜虎
# @Email : 1813366784@qq.com
# @Software : PyCharm
-------------------------------------------------
输入文件 : 开单明细模板.xlsx ==收货报表.xlsx
输出文件 : 当前时间日期的开单明细模板.xlsx
"""
import os
from datetime import datetime
import pandas as pd
import requests
from pandas import DataFrame
from utils import headers, params_login, columns_transport_dtl_covert, columns_transport_hdr_covert
params_Hdr = {
'selectType': 1,
'moduleCode': 'transportReport',
'moduleListId': 'transportReportHdr',
'module': 'transportReport',
'pageNum': 1,
'terminal': 'PC'
}
params_Dtl = {
'selectType': 1,
'moduleCode': 'transportReport',
'moduleListId': 'transportReportDtl',
'module': 'transportReport',
'pageNum': 1,
'pageSize': 100, # 默认应该足够
'terminal': 'PC'
}
if __name__ == '__main__':
url = "https://hdd.hddky.com/tms-hdd/token/login"
response = requests.post(url, data=params_login, headers=headers).json()
headers['Authorization'] = response['rows']['token']
transportTimeBgn = datetime(2024, 1, 25, 00, 00, 00).timestamp().__int__() * 1000
transportTimeEnd = datetime(2024, 1, 31, 23, 59, 59).timestamp().__int__() * 1000
params_Hdr['transportTimeBgn'] = transportTimeBgn
params_Hdr['transportTimeEnd'] = transportTimeEnd
url = "https://hdd.hddky.com/tms-hdd/report/voyageReportHdr"
response_Hdr = requests.post(url, data=params_Hdr, headers=headers).json()
params_Hdr['pageSize'] = response_Hdr['total']
response_Hdr = requests.post(url, data=params_Hdr, headers=headers).json()
receive_Hdr = DataFrame(response_Hdr['rows'])
receive_Hdr.rename(columns=columns_transport_hdr_covert, inplace=True)
receive_Hdr['发车时间'] = receive_Hdr['发车时间'].apply(lambda x: datetime.fromtimestamp(x / 1000))
receive_Hdr = receive_Hdr.reindex(columns=list(columns_transport_hdr_covert.values()))
if not (os.path.isdir(r'resources/temp')):
os.mkdir(r'resources/temp')
receive_Hdr.to_excel(r'resources/temp/发车统计.xlsx', index=False, startrow=1, engine='openpyxl')
params_Dtl['transportTimeBgn'] = transportTimeBgn
params_Dtl['transportTimeEnd'] = transportTimeEnd
url = 'https://hdd.hddky.com/tms-hdd/report/voyageReportDtl'
receive_Dtl = DataFrame()
for row in response_Hdr['rows']:
params_Dtl['voyageId'] = row['voyageId']
response_Dtl = requests.post(url, data=params_Dtl, headers=headers).json()
assert params_Dtl['pageSize'] >= response_Dtl['total'], "超过设置返回数量"
Dtl_inc = DataFrame(response_Dtl['rows'])
receive_Dtl = pd.concat([receive_Dtl, Dtl_inc], ignore_index=True)
receive_Dtl.rename(columns=columns_transport_dtl_covert, inplace=True)
receive_Dtl = receive_Dtl.reindex(columns=list(columns_transport_dtl_covert.values()))
receive_Dtl.to_excel(r'resources/temp/发车明细.xlsx', index=False, startrow=1, engine='openpyxl')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。