Python: get weather of cities
import requests
def get_wether(latitude, longitude):
response = requests.get(f"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}¤t=temperature_2m")
data = response.json()
return data['current']['temperature_2m']
paris_temp = get_wether(48.85, 2.35)
london_temp = get_wether(51.50, -0.12)
tokyo_temp = get_wether(35.68, 139.69)
bangalore_temp = get_wether(12.9629, 77.5775)
print(f"Paris: {paris_temp}°C")
print(f"London: {london_temp}°C")
print(f"Tokyo: {tokyo_temp}°C")
print(f"Bangalore: {bangalore_temp}°C")
Output
Paris: 15.9°C
London: 14.0°C
Tokyo: 22.5°C
Bangalore: 26.2°C