first commit
This commit is contained in:
parent
6bdba48fa5
commit
7f28fe580d
38 changed files with 452 additions and 0 deletions
38
api/build_qstring.py
Normal file
38
api/build_qstring.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue