JAMESPARK3 commited on
Commit
cfea38f
ยท
verified ยท
1 Parent(s): e0bd95e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
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
- new_data = get_weather_data()
510
- if new_data:
511
  st.session_state.api_failed = False
512
- st.session_state.weather_data = new_data
513
- st.session_state.last_api_call = datetime.utcnow().timestamp()
514
- st.rerun()
 
 
 
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