Commit 1efac53a by 王欣伟

提交审计、权益、供应链出货单数据处理逻辑

1 parent a3e4a069
......@@ -235,7 +235,7 @@ class HandelMain:
if __name__ == "__main__":
handle_month = '2023-07'
handle_month = '2023-09'
dedRes = False
diRes = False
urRes = False
......
import logging
import pandas as pdas
import os
import chardet
import math
import requests
from urllib.parse import urlparse
print("sys config " + __name__)
log_name = './log/imageequity/equityimagedeal.log'
log_format = '[%(asctime)s-%(filename)s-%(levelname)s:%(message)s]'
log_level = logging.DEBUG
log_mode = 'a'
logging.basicConfig(filename=log_name, format=log_format, level=log_level, filemode=log_mode, encoding='utf-8')
class equityImageDeal:
def __init__(self):
logging.info("init construct bean")
# 获取文件名,从URL的路径中提取
def getFileNameFromUrl(self, fileUrl):
url_path = urlparse(fileUrl).path
file_name = os.path.basename(url_path)
return file_name
def ospathinit(self, filePath):
# 使用 os.path.exists() 函数检查文件夹是否存在
if not os.path.exists(filePath):
# 如果文件夹不存在,创建它
os.makedirs(filePath)
print(f"文件夹 {filePath} 创建成功")
else:
print(f"文件夹 {filePath} 已存在")
def downloadImageFile(self, fileUrl, fileName):
# 发送HTTP GET请求获取文件内容
response = requests.get(fileUrl)
# 检查响应状态码是否为200,表示请求成功
if response.status_code == 200:
# 以二进制写入模式打开本地文件,然后写入响应内容
with open(fileName, "wb") as local_file:
local_file.write(response.content)
print(f"文件已下载到 {fileName}")
else:
print("下载失败,状态码:", response.status_code)
def dealImageData(self, excelFilePath, exportPath):
logging.info('excelFile:%s, exportPath:%s' %(excelFilePath, exportPath))
# 1. 读取文件内容
eqDataFrames = pdas.read_excel(excelFilePath)
for drow in eqDataFrames.itertuples():
# 购车发票地址 合同购买时里程数地址 行驶证主页地址 行驶证副页地址 其他资料地址
buyCarListUrl = drow.购车发票地址
buyCarMileageUrl = drow.合同购买时里程数地址
carCheckMainUrl = drow.行驶证主页地址
carCheckCommonUrl = drow.行驶证副页地址
carOtherUrlList = []
# 2. 初始化文件路径
currentFileExportPath = f'{exportPath}{drow.车架号}_{drow.合同号}'
self.ospathinit(currentFileExportPath)
# 3. 执行导出
if (drow.其他资料地址 is not None and pdas.isna(drow.其他资料地址) is False):
carOtherUrlList = drow.其他资料地址.split(',')
i = 1
for itemUrl in carOtherUrlList:
fileName = f'{currentFileExportPath}/其他-{i}-{self.getFileNameFromUrl(itemUrl)}'
self.downloadImageFile(itemUrl, fileName)
i+=1
if (buyCarListUrl is not None and pdas.isna(buyCarListUrl) is False):
fileName = f'{currentFileExportPath}/购车发票地址-{self.getFileNameFromUrl(buyCarListUrl)}'
self.downloadImageFile(buyCarListUrl, fileName)
if (buyCarMileageUrl is not None and pdas.isna(buyCarMileageUrl) is False):
fileName = f'{currentFileExportPath}/合同购买时里程数地址-{self.getFileNameFromUrl(buyCarMileageUrl)}'
self.downloadImageFile(buyCarMileageUrl, fileName)
if (carCheckMainUrl is not None and pdas.isna(carCheckMainUrl) is False):
fileName = f'{currentFileExportPath}/行驶证主页地址-{self.getFileNameFromUrl(carCheckMainUrl)}'
self.downloadImageFile(carCheckMainUrl, fileName)
if (carCheckCommonUrl is not None and pdas.isna(carCheckCommonUrl) is False):
fileName = f'{currentFileExportPath}/行驶证副页地址-{self.getFileNameFromUrl(carCheckCommonUrl)}'
self.downloadImageFile(carCheckCommonUrl, fileName)
# 打印日志
# print(buyCarListUrl, buyCarMileageUrl, carCheckMainUrl, carCheckCommonUrl, carOtherUrlList)
if __name__ == "__main__":
print('start deal equity image.')
eqImageDeal = equityImageDeal()
dealMonth = '202309'
fileName = '无忧权益订单数据20230915142850.xlsx'
excelFilePath = f'F:/eq/{dealMonth}/{fileName}'
exportPath = f'F:/eq/{dealMonth}/export/'
dealRes = eqImageDeal.dealImageData(excelFilePath, exportPath)
print('deal result:', dealRes)
\ No newline at end of file
......@@ -167,7 +167,7 @@ if __name__ == "__main__":
logging.info("start handle" + handleMain.handleDescription + ' the month:' + handleMain.handleMonth)
# 输出店面数据
# handleMain.proxySaasDYMerchantCount()
handleMain.proxySaasDYMerchantCount()
# 输出SAAS+与DJ重叠业务的店面数据
handleMain.proxyDyAndSaasPlusMerchantCount()
......@@ -318,5 +318,5 @@ if __name__ == "__main__":
dealMain.module_file_path = 'D:/work_doc/003 - 商务脚本/发货签收单-模板-rel.xlsx'
dealMain.defaultExportReleasePath = 'D:/work_doc/003 - 商务脚本/export_relaese/'
contentPath = 'D:/work_doc/003 - 商务脚本/2021年-2023年发货清单明细/2023年/'
contentPath = 'D:/work_doc/003 - 商务脚本/2021年-2023年发货清单明细/2023年7月/'
dealMain.dealContentFile(contentPath)
This diff could not be displayed because it is too large.
[2023-08-23 10:09:37,186-connectionpool.py-DEBUG:Starting new HTTPS connection (1): api.weixin.qq.com:443]
[2023-08-23 10:09:37,641-connectionpool.py-DEBUG:https://api.weixin.qq.com:443 "GET /cgi-bin/token?grant_type=client_credential&appid=wxcad686d44f4c8c4d&secret=6f72dbed5b5259d518c9af2b1a15f53d HTTP/1.1" 200 73]
[2023-08-23 11:29:30,173-connectionpool.py-DEBUG:Starting new HTTPS connection (1): api.weixin.qq.com:443]
[2023-08-23 11:29:30,276-connectionpool.py-DEBUG:https://api.weixin.qq.com:443 "GET /cgi-bin/user/get?access_token=71_PJ5AK7jEg0snTcnLwf-M9YwM0KVwEdzEhZ0CjetFTtiyv4pWfaGxfgUC7IBFfRKDusD97dtzH1HZjNllly_qHJSUw_hE7nGyA4yIjXhPS0mCz_8ZEqHlsRcD1zYKALdAEARHS&next_openid= HTTP/1.1" 200 81]
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!