We will write a script that retrieves weather data for your city and displays it in a convenient format.
First, we need the
requests library for network operations. If it's not installed, install it via the terminal with the command:
pip install requests
Import the module and define a function that retrieves data from the Open-Meteo API (no key required) for specific coordinates:
import requests
def get_weather(lat, lon):
url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}¤t_weather=true"
return requests.get(url).json()['current_weather']
Specify the coordinates of your city (for example, Moscow):
moscow_coords = (55.75, 37.62)
Display the temperature and wind speed:
weather = get_weather(*moscow_coords)
print(f"Temperature: {weather['temperature']}°C, Wind speed: {weather['windspeed']} km/h")
🔥 Get fresh weather data without registration or passwords — useful for your own projects or bots!🚪 @DataScience4