Files
wiki_crawler/nodes/parse_register.py
2025-12-29 14:42:33 +08:00

29 lines
729 B
Python

import json
def parse_response(status_code: float, body: str):
'''
检查状态码和约定的返回值
并且返回正确的body
'''
if status_code != 200:
raise Exception(f"注册任务失败,状态码:{status_code}")
data = json.loads(body)
if "code" not in data or data["code"] != 1:
raise Exception(f"注册任务失败,返回值:{body}")
return data["data"]
def main(status_code: float, body: str):
try:
data = parse_response(status_code, body)
except Exception as e:
raise e
task_id = data["task_id"]
is_new_task = data["is_new_task"]
return {
"task_id": task_id,
"is_new_task": is_new_task
}