Чтобы узнать погоду на завтра в Гранд-Прейри, штат Техас, вы можете использовать различные методы. Вот несколько примеров на разных языках программирования:
-
Python с использованием библиотеки
requests:import requests def get_weather(): url = "https://api.weatherapi.com/v1/forecast.json?key=YOUR_API_KEY&q=Grand%20Prairie%20Texas&days=2" response = requests.get(url) data = response.json() tomorrow = data['forecast']['forecastday'][1]['day'] weather_condition = tomorrow['condition']['text'] temperature_celsius = tomorrow['avgtemp_c'] temperature_fahrenheit = tomorrow['avgtemp_f'] return f"Tomorrow's weather in Grand Prairie, Texas: {weather_condition}. Average temperature: {temperature_celsius}°C ({temperature_fahrenheit}°F)." print(get_weather()) -
JavaScript с использованием библиотеки
axios:const axios = require('axios'); function getWeather() { const url = "https://api.weatherapi.com/v1/forecast.json?key=YOUR_API_KEY&q=Grand%20Prairie%20Texas&days=2"; return axios.get(url) .then(response => { const tomorrow = response.data.forecast.forecastday[1].day; const weatherCondition = tomorrow.condition.text; const temperatureCelsius = tomorrow.avgtemp_c; const temperatureFahrenheit = tomorrow.avgtemp_f; return `Tomorrow's weather in Grand Prairie, Texas: ${weatherCondition}. Average temperature: ${temperatureCelsius}°C (${temperatureFahrenheit}°F).`; }) .catch(error => { console.log(error); }); } getWeather().then(result => console.log(result));
Обратите внимание, что в приведенных выше примерах вам необходимо заменить «YOUR_API_KEY» реальным ключом API, полученным от поставщика метеорологических услуг.