-
Notifications
You must be signed in to change notification settings - Fork 29
/
check.py
36 lines (28 loc) · 1.16 KB
/
check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import requests
import base64
import logging
# 设置日志级别
logging.basicConfig(level=logging.INFO)
URL = "http://localhost:8000/ai_check"
input_dir = "./input"
output_dir = "./output"
os.makedirs(input_dir, exist_ok=True)
os.makedirs(output_dir, exist_ok=True)
# 使用os模块遍历目录
for root, dirs, files in os.walk(input_dir):
for file in files:
if file.endswith(".docx"):
# 检查文件是否已经被处理过
if os.path.exists(os.path.join(output_dir, file)):
logging.info(f"文件 {file} 已处理过,跳过此文件")
continue
logging.info(f"开始处理文件 {file}")
input_file = os.path.join(root, file)
with open(input_file, "rb") as f:
response = requests.post(URL, files={"file": ("a.docx", f, "application/octet-stream")})
# 将结果保存到 output_dir
output_file = os.path.join(output_dir, file)
with open(output_file, "wb") as f:
f.write(base64.b64decode(response.text))
logging.info(f"处理结束,结果已保存到 {output_file}")