import re
import yaml
import json

curl_example = r"""
curl 'https://cli1.mobgi.com/Baidu/Advertiser/getList' \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'Accept-Language: zh-CN,zh;q=0.9' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json;charset=UTF-8' \
  -b 'userId=100362; chuangliang_session=42YqwTsP4e98gPzwcQ3u83vQE984OnqvER2pnAxk; idea_token=b5555f58-6db0-11f0-b1e3-00163e4f2804' \
  -H 'Origin: https://cl.mobgi.com' \
  -H 'Referer: https://cl.mobgi.com/' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Site: same-site' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36' \
  -H 'client-user: 100362' \
  -H 'ff-request-id: 20250731201346e309169d13454d12bca544a779fadbb0' \
  -H 'main-user-id: 100362' \
  -H 'sec-ch-ua: "Not)A;Brand";v="8", "Chromium";v="138", "Google Chrome";v="138"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"' \
  --data-raw '{"conditions":"{\"companys\":[],\"cl_project_id\":[],\"optimize_user_id\":[],\"keyword\":\"\"}","start_date":"2025-07-31","end_date":"2025-07-31","page":1,"page_size":20,"total_count":2,"total_page":1,"sort_field":"","sort_direction":"","data_type":"list"}'
"""

# 步骤1：提取原始数据
pattern = r"--data-raw\s+'(.*?)'"
match = re.search(pattern, curl_example, re.DOTALL)
if not match:
    raise ValueError("未找到--data-raw数据")

data_raw_str = match.group(1)
print(data_raw_str)
print(json.loads(data_raw_str))
yaml_data = yaml.dump(data_raw_str)
print(yaml_data)
