import os
import json
import requests
# 获取userCode
def getUserCode(folderPath):
res = []
for fileName in os.listdir(folderPath):
filePath = os.path.join(folderPath, fileName)
with open(filePath, 'r') as file:
lines = file.readlines()
for line in lines:
stripLine = line.rstrip('\n')
res.append(stripLine)
file.close()
return res
# 根据userCode删除用户
def deleteByUserCode(apiUrl, userCodeLists):
total = len(userCodeLists)
cnt = 0
for userCode in userCodeLists:
cnt = cnt + 1
apiPath = apiUrl + '?userCode=' + str(userCode)
print("apiPath", apiPath)
# 使用files参数上传文件
response = requests.delete(apiPath)
# 检查响应状态码
if response.status_code == 200:
try:
print(f"res", response.json())
except KeyError:
print(f"删除失败")
else:
print(f"查询失败,状态码: {response.status_code}")
print("total", total, "current", cnt)
if __name__ == "__main__":
path = r"C:\Users\Administrator\Desktop\image\txt"
# Step1: 获取userCode
userCodeLists = getUserCode(path)
# Step2: 删除用户
deleteByUserCode(r"http://192.168.20.56:9999/api/deleteByUserCode", userCodeLists)