-
Notifications
You must be signed in to change notification settings - Fork 0
/
Weather Project
55 lines (50 loc) · 2.37 KB
/
Weather Project
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import requests
city_name = input("Enter your city name: ") # Taking city name from the user
API_key = "86f4b579740493093a2c9c7de3b8ff7c" # Confidential API Id
req = requests.get('https://api.openweathermap.org/data/2.5/weather?q={}&appid={}'.format(city_name, API_key))
# print(req)
req_data = req.json()
if req_data['cod'] == '404':
print("Invalid City: {}, Please check your city name.".format(city_name))
else:
coordinates_of_location_longitude = req_data['coord']['lon']
coordinates_of_location_latitude = req_data['coord']['lat']
country = req_data['sys']['country']
s_rise = req_data['sys']['sunrise']
s_set = req_data['sys']['sunset']
time_zone = req_data['timezone']
min_temp = req_data['main']['temp_min'] - 273.15
temp = req_data['main']['temp'] - 273.15
max_temp = req_data['main']['temp_max'] - 273.15
weather_desc = req_data['weather'][0]['description']
pressure = req_data['main']['pressure']
humidity = req_data['main']['humidity']
wind_speed = req_data['wind']['speed']
print()
print()
print('..............................................................................')
print('>>>>>>>>>>....BELOW IS THE WEATHER REPORT OF THE CITY {}....<<<<<<<<<<<'.format(city_name))
print('..............................................................................')
print()
print('Co-ordinates: Longitude - {}'.format(coordinates_of_location_longitude))
print(' Latitude - {}'.format(coordinates_of_location_latitude))
print()
print('Country: {}'.format(country))
print()
print(' SUN \\ ')
print(' / \\ ')
print(' / \\ ')
print(' / \\ ')
print(' / \\ ')
print(' / SUN')
print('{} {}'.format(s_rise, s_set))
print()
print('Time Zone: {}\n'.format(time_zone))
print('Minimum Temperature --> {:.2f} {:.2f} <-- Maximum Temperature'.format(min_temp, max_temp))
print()
print(' {:.2f}'.format(temp))
print(' Average Temperature\n')
print('Weather Description: {}\n'.format(weather_desc))
print('Pressure: ', pressure)
print('Humidity: ', humidity)
print('Wind Speed: ', wind_speed)