import httpx, json, openpyxl, time
deeplx_api = “http://127.0.0.1:1188/translate”
wb = openpyxl.load_workbook(“c2023.xlsx”)
sheet = wb[“Sheet1”]
for i in range(sheet.max_row):
row_line = str(i + 1)
time.sleep(2)
data = {
“text”: sheet[“A” + row_line].value,
“source_lang”: “ZH”,
“target_lang”: “EN”,
}
post_data = json.dumps(data)
r = httpx.post(url=deeplx_api, data=post_data).text
data = json.loads(r)
name = data[“data”]
print(“data: “, name)
sheet[“B” + row_line] = name
print(i)
wb.save(“translated.xlsx”)