0o7Hunk commited on
Commit
4906a14
Β·
verified Β·
1 Parent(s): 4e182d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -3,7 +3,8 @@ import requests
3
  import geocoder
4
 
5
  # πŸ‘‰ Put your API key here
6
- API_KEY = "API_KEY"
 
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") != 200:
 
 
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