Фраза «azerbaycan hava durumu» на турецком языке переводится как «погода в Азербайджане». Ниже приведены несколько методов, которые можно использовать для программного получения информации о погоде в Азербайджане, а также примеры кода:
-
Использование API – OpenWeatherMap:
import requests def get_weather(city): api_key = "YOUR_API_KEY" base_url = "https://api.openweathermap.org/data/2.5/weather" params = { "q": city, "appid": api_key, "units": "metric" # You can change the units to imperial if desired } response = requests.get(base_url, params=params) data = response.json() if data["cod"] == 200: temperature = data["main"]["temp"] weather_description = data["weather"][0]["description"] return f"The temperature in {city} is {temperature}°C. {weather_description}." else: return "Unable to retrieve weather information." city = "Baku" # Replace with the desired city in Azerbaijan print(get_weather(city)) -
Использование библиотеки веб-скрапинга – BeautifulSoup:
import requests from bs4 import BeautifulSoup def get_weather(city): url = f"https://www.weather-forecast.com/locations/{city}/forecasts/latest" response = requests.get(url) soup = BeautifulSoup(response.content, "html.parser") weather_forecast = soup.find(class_="b-forecast__table-description-content").text.strip() return weather_forecast city = "Baku" # Replace with the desired city in Azerbaijan print(get_weather(city))
Это всего лишь пара примеров. Существует множество других способов программного получения информации о погоде. Не забудьте заменить «YOUR_API_KEY» фактическим ключом API, если вы решите использовать API OpenWeatherMap.