77 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			77 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Python
		
	
	
	
| # -*- coding: utf-8 -*-
 | |
| 
 | |
| """
 | |
| 普康健康_影像处理
 | |
| """
 | |
| 
 | |
| # 加载模块
 | |
| 
 | |
| from pathlib import Path
 | |
| 
 | |
| import zipfile
 | |
| 
 | |
| from utils.pandas_extension import open_csv, save_as_workbook
 | |
| 
 | |
| 
 | |
| if __name__ == "__main__":
 | |
| 
 | |
|     print("正在本地加载待处理影像信息...", end="")
 | |
| 
 | |
|     dataframe = open_csv(file_name="待处理影像信息.csv")
 | |
| 
 | |
|     dataframe["处理结果"] = "待处理"
 | |
| 
 | |
|     # 统计行数
 | |
|     rows = dataframe.shape[0]
 | |
| 
 | |
|     print(f"已完成,行数为 {rows}")
 | |
| 
 | |
|     print("正在处理影像件...", end="")
 | |
| 
 | |
|     for index, row in dataframe.iterrows():
 | |
| 
 | |
|         # 推送月份
 | |
|         push_month = row["推送月份"]
 | |
| 
 | |
|         # 影像件名称
 | |
|         image_name = row["影像件名称"]
 | |
| 
 | |
|         # 推送山东国网影像件名称
 | |
|         push_name = row["推送山东国网影像件名称"]
 | |
| 
 | |
|         # 压缩包名称
 | |
|         zip_name = row["压缩包名称"]
 | |
| 
 | |
|         # 处理结果
 | |
|         result = "发生其它异常"
 | |
| 
 | |
|         # 创建影像件PATH对象
 | |
|         image = Path(f"images/{push_month}/{image_name}")
 | |
| 
 | |
|         # 若影像件PATH对象不存在则处理结果为“未找到影像件”
 | |
|         if not image.exists():
 | |
| 
 | |
|             result = "未找到影像件"
 | |
| 
 | |
|             continue
 | |
| 
 | |
|         # ZIP压缩
 | |
|         with zipfile.ZipFile(file=f"zips/{zip_name}", mode='w', compression=zipfile.ZIP_DEFLATED) as file:
 | |
| 
 | |
|             # 压缩包内影像件名称为推送山东国网影像件名称
 | |
|             file.write(image, arcname=push_name)  # 指定在压缩包内影像件名称
 | |
| 
 | |
|             result = "处理成功"
 | |
| 
 | |
|         dataframe.loc[index, "处理结果"] = result
 | |
| 
 | |
|     print("已完成")
 | |
| 
 | |
|     print("正在保存为工作簿...", end="")
 | |
| 
 | |
|     save_as_workbook(worksheets=[("Sheet1", dataframe)], workbook_name="results.xlsx")
 | |
| 
 | |
|     print("已完成")
 | |
| 
 | |
| 
 |