Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,8 @@ import requests
|
|
| 3 |
import geocoder
|
| 4 |
|
| 5 |
# π Put your API key here
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
# -------- FUNCTIONS --------
|
| 9 |
def get_weather(city):
|
|
@@ -37,8 +38,12 @@ city = st.text_input("Enter City Name", city)
|
|
| 37 |
if city:
|
| 38 |
weather = get_weather(city)
|
| 39 |
|
| 40 |
-
if weather.get("cod")
|
|
|
|
|
|
|
| 41 |
st.error("β City not found")
|
|
|
|
|
|
|
| 42 |
else:
|
| 43 |
st.subheader(f"π Weather in {city}")
|
| 44 |
|
|
|
|
| 3 |
import geocoder
|
| 4 |
|
| 5 |
# π Put your API key here
|
| 6 |
+
import os
|
| 7 |
+
API_KEY = os.getenv("API_KEY")
|
| 8 |
|
| 9 |
# -------- FUNCTIONS --------
|
| 10 |
def get_weather(city):
|
|
|
|
| 38 |
if city:
|
| 39 |
weather = get_weather(city)
|
| 40 |
|
| 41 |
+
if weather.get("cod") == 401:
|
| 42 |
+
st.error("β Invalid API Key")
|
| 43 |
+
elif weather.get("cod") == "404":
|
| 44 |
st.error("β City not found")
|
| 45 |
+
elif weather.get("cod") != 200:
|
| 46 |
+
st.error(f"Error: {weather.get('message')}")
|
| 47 |
else:
|
| 48 |
st.subheader(f"π Weather in {city}")
|
| 49 |
|