-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeatherForecast.py
More file actions
34 lines (24 loc) · 1.17 KB
/
WeatherForecast.py
File metadata and controls
34 lines (24 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests
# Set the API key
api_key = "4081103fa088c592aca6e065e4ff5657"
# Get the user input
location = input("Inserisci la località: ")
# Set the units
units = "metric"
# Make the request
response = requests.get("https://api.openweathermap.org/data/2.5/weather?q=" + location + "&appid=" + api_key + "&units=" + units)
# Check the response status code
if response.status_code == 200:
# Get the response data
weather_data = response.json()
# Print the weather information
print("Il tempo atmosferico a " + location + " è questo :")
print("* Temperatura: " + str(weather_data["main"]["temp"]) + "°C")
print("* Temperatura percepita: " + str(weather_data["main"]["feels_like"]) + "°C")
print("* Umidità: " + str(weather_data["main"]["humidity"]) + "%")
print("* Pressione: " + str(weather_data["main"]["pressure"]) + "hPa")
print("* Velocità del vento " + str(weather_data["wind"]["speed"]) + "m/s")
print("* Nuvolosità: " + str(weather_data["clouds"]["all"]) + "%")
print("* Descrizione: " + weather_data["weather"][0]["description"])
else:
print("Error: " + str(response.status_code))