加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
gen_fa_che_report.py 3.14 KB
一键复制 编辑 原始数据 按行查看 历史
Administrator 提交于 2024-02-19 10:31 . init
# -*- 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')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化