-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.py
41 lines (27 loc) · 1.08 KB
/
weather.py
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
import os
import requests
API_KEY = os.getenv("OPENWEATHERMAP_API_KEY")
class City:
def __init__(self,name, lat, lon, units="metric"):
self.name=name
self.lat=lat
self.lon=lon
self.units=units
self.get_data()
self.temp_print()
def get_data(self):
try:
response = requests.get(f"https://api.openweathermap.org/data/2.5/weather?units={self.units}&lat={self.lat}&lon={self.lon}&appid={API_KEY}")
except:
print("No internet access 😊")
self.response_json=response.json()
self.temp=self.response_json['main']['temp']
self.temp_min=self.response_json['main']['temp_min']
self.temp_max=self.response_json['main']['temp_max']
def temp_print(self):
print(f"\nIn {self.name} it it currently {self.temp} ℃")
print(f"Today's High: {self.temp_max} ℃")
print(f"Today's Low: {self.temp_min} ℃ \n")
my_city=City("Paderborn",51.7189,8.7575)
vacation_city=City('Vadodara', 22.310696,73.192635)
#print(vacation_city.response_json)