first commit

main
Dawn1Ocean 2024-11-11 17:12:56 +08:00
commit 415e155bf4
3 changed files with 53 additions and 0 deletions

10
README.md 100644
View File

@ -0,0 +1,10 @@
# ZJUEVA 财外报销表格下载脚本
## 功能
将指定文件夹中所有的`.xls` / `.xlsx` 文件当中的以`发票-付款记录-购买记录`为一组的三份文件下载下来(如有)并放在一定命名规范的文件夹中。
## 所需包(已打包在`.exe`中)
- requests
- pandas

BIN
main.exe 100644

Binary file not shown.

43
main.py 100644
View File

@ -0,0 +1,43 @@
from pandas import read_excel
from requests import get
from sys import exit
import os
def download(url, pic_path_name):
format_file = url.split(".")[-1].lower()
if format_file not in ["png", "pdf", "jpg", "jpeg"]:
input("文件格式出现错误,请联系程序开发者!")
exit()
result = get(url)
file = pic_path_name + "." + format_file
with open(file, "wb") as f:
f.write(result.content)
if __name__ == "__main__":
dir_path = input("请输入 .xls / .xlsx 文件所在文件夹的绝对或相对路径:")
for root, _, files in os.walk(dir_path):
for file in files:
if file.lower().endswith('.xls') or file.lower().endswith('.xlsx'):
excel_path = os.path.join(root, file)
df = read_excel(excel_path)
print("正在处理 " + file + " ...")
dir_name = file.split('.')[0]
os.mkdir(dir_name)
for one in range(len(df)):
path_name = './' + dir_name + '/' + df["3、购买日期"][one] + "" + str(df["4、金额"][one]) + "" + df["5、物品"][one] + " " + df["1、您的姓名"][one]
if not os.path.exists(path_name):
os.mkdir(path_name)
# 处理购买记录截图
buy_prt_sc = df["6、购买记录截图"][one]
if buy_prt_sc != "(跳过)":
download(buy_prt_sc, "./" + path_name + "/购买记录截图")
# 处理支付记录截图
pay_prt_sc = df["7、支付记录截图"][one]
if pay_prt_sc != "(跳过)":
download(pay_prt_sc, "./" + path_name + "/支付记录截图")
# 处理发票图片
pdf = df["9、发票图片"][one]
if pdf != "(空)":
download(pdf, "./" + path_name + "/发票图片")
print(f"共计{len(df)}, 已完成{one + 1}")
print(file + " 处理完毕!")