Spaces:
Sleeping
Sleeping
JAMESPARK3
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -204,6 +204,18 @@ def check_network_status():
|
|
204 |
return response.status_code == 200
|
205 |
except httpx.RequestError:
|
206 |
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
|
208 |
@st.cache_data(ttl=300)
|
209 |
def get_weather_data():
|
@@ -504,14 +516,17 @@ def show_weather_info(data):
|
|
504 |
|
505 |
with col2:
|
506 |
st.button("์๊ฐ๋๋ณ ์จ๋ ๋ณด๊ธฐ", on_click=lambda: st.session_state.update({'current_section': 'temperature'}))
|
|
|
507 |
with col3:
|
508 |
if st.button("API ์๋ต ์ฒดํฌ"):
|
509 |
-
|
510 |
-
if new_data:
|
511 |
st.session_state.api_failed = False
|
512 |
-
|
513 |
-
|
514 |
-
|
|
|
|
|
|
|
515 |
# session_state์ API ์คํจ ์๊ฐ ์ ์ฅ์ ์ํ ๋ณ์ ์ถ๊ฐ
|
516 |
if 'api_failed_time' not in st.session_state:
|
517 |
st.session_state.api_failed_time = None
|
|
|
204 |
return response.status_code == 200
|
205 |
except httpx.RequestError:
|
206 |
return False
|
207 |
+
|
208 |
+
def check_api_status():
|
209 |
+
try:
|
210 |
+
url = "http://openapi.seoul.go.kr:8088/77544e69764a414d363647424a655a/xml/citydata/1/5/์ ๋ฆผ์ญ"
|
211 |
+
response = requests.get(url, timeout=5)
|
212 |
+
if response.status_code == 200:
|
213 |
+
data = xmltodict.parse(response.text)
|
214 |
+
if data.get('SeoulRtd.citydata', {}).get('RESULT', {}).get('MESSAGE') == "์ ์ ์ฒ๋ฆฌ๋์์ต๋๋ค.":
|
215 |
+
return True
|
216 |
+
return False
|
217 |
+
except:
|
218 |
+
return False
|
219 |
|
220 |
@st.cache_data(ttl=300)
|
221 |
def get_weather_data():
|
|
|
516 |
|
517 |
with col2:
|
518 |
st.button("์๊ฐ๋๋ณ ์จ๋ ๋ณด๊ธฐ", on_click=lambda: st.session_state.update({'current_section': 'temperature'}))
|
519 |
+
# API ์๋ต ์ฒดํฌ ๋ฒํผ ๋ถ๋ถ ์์
|
520 |
with col3:
|
521 |
if st.button("API ์๋ต ์ฒดํฌ"):
|
522 |
+
if check_api_status():
|
|
|
523 |
st.session_state.api_failed = False
|
524 |
+
new_data = get_weather_data()
|
525 |
+
if new_data:
|
526 |
+
st.session_state.weather_data = new_data
|
527 |
+
st.session_state.last_api_call = datetime.utcnow().timestamp()
|
528 |
+
st.rerun()
|
529 |
+
|
530 |
# session_state์ API ์คํจ ์๊ฐ ์ ์ฅ์ ์ํ ๋ณ์ ์ถ๊ฐ
|
531 |
if 'api_failed_time' not in st.session_state:
|
532 |
st.session_state.api_failed_time = None
|