38 lines
No EOL
1 KiB
Python
38 lines
No EOL
1 KiB
Python
import urllib.parse
|
|
|
|
def build_query_string(data: dict) -> str:
|
|
required_keys = [
|
|
"profile",
|
|
"pred_type",
|
|
"launch_datetime",
|
|
"launch_latitude",
|
|
"launch_longitude",
|
|
"launch_altitude",
|
|
"ascent_rate",
|
|
"burst_altitude",
|
|
"descent_rate"
|
|
]
|
|
|
|
# Проверяем, что все ключи на месте
|
|
missing_keys = [key for key in required_keys if key not in data]
|
|
if missing_keys:
|
|
raise ValueError(f"Missing required keys: {', '.join(missing_keys)}")
|
|
|
|
# Собираем строку запроса
|
|
return urllib.parse.urlencode({k: data[k] for k in required_keys})
|
|
|
|
# Пример:
|
|
json_data = {
|
|
"profile": "standard_profile",
|
|
"pred_type": "single",
|
|
"launch_datetime": "2025-03-16T08:47:00Z",
|
|
"launch_latitude": "56.6992",
|
|
"launch_longitude": "38.8247",
|
|
"launch_altitude": "0",
|
|
"ascent_rate": "5",
|
|
"burst_altitude": "30000",
|
|
"descent_rate": "5"
|
|
}
|
|
|
|
query_string = build_query_string(json_data)
|
|
print(query_string) |