-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
29 lines (24 loc) · 1005 Bytes
/
app.py
File metadata and controls
29 lines (24 loc) · 1005 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
# Imports.
import requests
# OpenWeather API key.
API_KEY = ''
user_selected_city = ''
while (not user_selected_city):
user_selected_city = input('Enter city: ')
if (user_selected_city == ''):
print('Please try again.')
# API call.
weather_data = requests.get(
f'https://api.openweathermap.org/data/2.5/weather?q={user_selected_city}&units=imperial&APPID={API_KEY}'
)
# Display API call results.
if (weather_data.json()['cod'] == '404'):
print('No city found. Please try again.')
else:
current_weather = weather_data.json()['weather'][0]['main']
current_temperature = round(weather_data.json()['main']['temp'])
current_feels_like_temperature = round(weather_data.json()['main']['feels_like'])
user_selected_city = weather_data.json()['name']
print(f'The current weather in {user_selected_city} is: {current_weather}.')
print(f'The temperature is {current_temperature}°F and feels like {current_feels_like_temperature}°F.')
print('Thank you!')