-
Notifications
You must be signed in to change notification settings - Fork 303
Expand file tree
/
Copy pathweather.py
More file actions
31 lines (19 loc) · 727 Bytes
/
weather.py
File metadata and controls
31 lines (19 loc) · 727 Bytes
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
from dotenv import load_dotenv
from pprint import pprint
import requests
import os
load_dotenv()
def get_current_weather(city="Kansas City"):
request_url = f'http://api.openweathermap.org/data/2.5/weather?appid={os.getenv("API_KEY")}&q={city}&units=imperial'
weather_data = requests.get(request_url).json()
return weather_data
if __name__ == "__main__":
print('\n*** Get Current Weather Conditions ***\n')
city = input("\nPlease enter a city name: ")
# Check for empty strings or string with only spaces
# This step is not required here
# if not bool(city.strip()):
# city = "Kansas City"
weather_data = get_current_weather(city)
print("\n")
pprint(weather_data)