alexohduke commited on
Commit
664dbd2
·
verified ·
1 Parent(s): f59122b

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +15 -16
src/streamlit_app.py CHANGED
@@ -5,33 +5,32 @@ import requests
5
 
6
  load_dotenv()
7
  API_KEY = os.getenv("API_KEY")
8
- st.write(API_KEY)
9
  url = f"https://api.openweathermap.org/data/2.5/weather"
10
  if "cities" not in st.session_state:
11
  st.session_state.cities = []
12
  st.title("Weather App PRO")
13
- city_input = st.text_input("Find City Weather", "Pyongyang")
14
- if st.button("Add Expander"):
15
- if city_input: # Only add if the input is not empty
16
- st.session_state.cities.append(city_input)
17
- st.success("Expander added!")
18
- else:
19
- st.warning("Please enter some content.")
20
 
 
21
  for idx, city in enumerate(st.session_state.cities):
22
- with st.expander(f"Weather from {city}"):
23
- params = {
24
  "q": city,
25
  "appid": API_KEY,
26
  "units": "metric" # temperature in Celsius
27
  }
28
- response = requests.get(url, params)
29
- if response.status_code !=200:
30
- st.write(F"{city} not found in API")
31
- st.write(response.content)
32
- else:
33
  data = response.json()
34
  for key, value in data['main'].items():
35
  st.write(f"{key}: {value}")
36
  st.write(f"Description: {data['weather'][0]['description']}")
37
-
 
 
 
 
5
 
6
  load_dotenv()
7
  API_KEY = os.getenv("API_KEY")
8
+
9
  url = f"https://api.openweathermap.org/data/2.5/weather"
10
  if "cities" not in st.session_state:
11
  st.session_state.cities = []
12
  st.title("Weather App PRO")
13
+ city_input = st.text_input("Find City Weather", "Durham")
14
+ if city_input: # Only add if the input is not empty
15
+ st.session_state.cities.append(city_input)
16
+ else:
17
+ st.warning("Please enter some content.")
 
 
18
 
19
+ st.header(f"City Weather")
20
  for idx, city in enumerate(st.session_state.cities):
21
+ params = {
 
22
  "q": city,
23
  "appid": API_KEY,
24
  "units": "metric" # temperature in Celsius
25
  }
26
+ response = requests.get(url, params)
27
+ if response.status_code ==200:
28
+ with st.expander(f"{city}"):
 
 
29
  data = response.json()
30
  for key, value in data['main'].items():
31
  st.write(f"{key}: {value}")
32
  st.write(f"Description: {data['weather'][0]['description']}")
33
+ else:
34
+ st.session_state.cities.remove(city)
35
+ # st.write(F"{city} not found in API")
36
+