API Connection to Server
Урок 8 из 10 курса API на Python на Coddy.
Задание
СреднеOpenWeatherMap обычно требует API-ключ, но в учебных целях мы будем использовать бесплатную альтернативу, не требующую регистрации: Open-Meteo API.
Отправьте GET-запрос на: https://api.open-meteo.com/v1/forecast
Добавьте следующие параметры, используя params:
{
"latitude": 52.52,
"longitude": 13.41,
"current_weather": "true"
}Сохраните объект requests.get() в переменную с именем response
Обработайте ответ с помощью response.json() и сохраните его в переменную с именем data
Выведите текущую температуру, обратившись к: data["current_weather"]["temperature"]
Попробуйте сами
import requests
# Step 1: Send GET request with parameters
response = requests.get(
# Your URL here
params={
# Your parameters here
}
)
# Step 2: Parse JSON response
data = # Your code here
# Step 3: Print current temperature
print("Current temperature:", data["current_weather"]["temperature"], "°C")Все уроки раздела API на Python
3Weather Fetch API Program
API Connection to ServerGET Request to ServerDisplaying Appropriate Results