JAMESPARK3 commited on
Commit
ccb688a
Β·
verified Β·
1 Parent(s): 9517d51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -12
app.py CHANGED
@@ -520,16 +520,18 @@ def show_weather_info(data):
520
  status_color = "#FF0000"
521
  status_text = "λ„€νŠΈμ›Œν¬ μ—°κ²° μ—†μŒ"
522
  else:
 
523
  if not st.session_state.api_failed:
524
  status_color = "#00AA00"
525
- status_text = "API 정상"
526
- st.session_state.api_failed_time = None
 
527
  else:
528
  status_color = "#FF0000"
529
- if st.session_state.api_failed_time is None:
530
- st.session_state.api_failed_time = datetime.now()
531
- failed_time = st.session_state.api_failed_time.strftime('%Y-%m-%d %H:%M')
532
- status_text = f"API 응닡 μ—†μŒ({failed_time} λ°œμƒ)"
533
 
534
  # API μƒνƒœ ν‘œμ‹œλ₯Ό μœ„ν•œ κ³ μœ ν•œ 클래슀λ₯Ό μ‚¬μš©
535
  st.markdown("""
@@ -886,6 +888,9 @@ def get_weather_forecast(forecast_data_str, current_time_str):
886
 
887
 
888
  def main():
 
 
 
889
  if 'current_section' not in st.session_state:
890
  st.session_state.current_section = 'weather'
891
  st.session_state.last_api_call = 0
@@ -954,10 +959,7 @@ def main():
954
 
955
  # μžλ™ μƒˆλ‘œκ³ μΉ¨μ„ μœ„ν•œ 타이머
956
  with refresh_placeholder:
957
- if time_since_last_call < 300:
958
- remaining_time = 300 - time_since_last_call
959
- time.sleep(min(remaining_time, 300)) # κ·Έλž˜ν”„ 5λΆ„λ§ˆλ‹€ λ Œλ”λ§
960
-
961
  # λ„€νŠΈμ›Œν¬ μƒνƒœ 체크 및 API μƒνƒœ μ—…λ°μ΄νŠΈ
962
  network_ok = check_network_status()
963
  if network_ok:
@@ -965,12 +967,17 @@ def main():
965
  new_data = get_weather_data()
966
  if new_data:
967
  st.session_state.api_failed = False
 
 
 
968
  else:
969
  st.session_state.api_failed = True
970
  except:
971
  st.session_state.api_failed = True
972
-
973
- st.rerun()
 
 
974
 
975
  if __name__ == "__main__":
976
  main()
 
520
  status_color = "#FF0000"
521
  status_text = "λ„€νŠΈμ›Œν¬ μ—°κ²° μ—†μŒ"
522
  else:
523
+ current_time = datetime.utcnow() + timedelta(hours=9) # KST
524
  if not st.session_state.api_failed:
525
  status_color = "#00AA00"
526
+ st.session_state.api_status_time = current_time
527
+ status_time = st.session_state.api_status_time.strftime('%Y-%m-%d %H:%M')
528
+ status_text = f"API 정상({status_time} 성곡)"
529
  else:
530
  status_color = "#FF0000"
531
+ if st.session_state.api_status_time is None:
532
+ st.session_state.api_status_time = current_time
533
+ status_time = st.session_state.api_status_time.strftime('%Y-%m-%d %H:%M')
534
+ status_text = f"API 응닡 μ—†μŒ({status_time} λ°œμƒ)"
535
 
536
  # API μƒνƒœ ν‘œμ‹œλ₯Ό μœ„ν•œ κ³ μœ ν•œ 클래슀λ₯Ό μ‚¬μš©
537
  st.markdown("""
 
888
 
889
 
890
  def main():
891
+ if 'api_status_time' not in st.session_state:
892
+ st.session_state.api_status_time = None
893
+
894
  if 'current_section' not in st.session_state:
895
  st.session_state.current_section = 'weather'
896
  st.session_state.last_api_call = 0
 
959
 
960
  # μžλ™ μƒˆλ‘œκ³ μΉ¨μ„ μœ„ν•œ 타이머
961
  with refresh_placeholder:
962
+ if time_since_last_call >= 300: # 5뢄이 μ§€λ‚¬μœΌλ©΄
 
 
 
963
  # λ„€νŠΈμ›Œν¬ μƒνƒœ 체크 및 API μƒνƒœ μ—…λ°μ΄νŠΈ
964
  network_ok = check_network_status()
965
  if network_ok:
 
967
  new_data = get_weather_data()
968
  if new_data:
969
  st.session_state.api_failed = False
970
+ st.session_state.weather_data = new_data
971
+ st.session_state.last_api_call = current_timestamp
972
+ st.rerun()
973
  else:
974
  st.session_state.api_failed = True
975
  except:
976
  st.session_state.api_failed = True
977
+
978
+ time.sleep(60) # 1λΆ„λ§ˆλ‹€ 체크
979
+ st.rerun()
980
+
981
 
982
  if __name__ == "__main__":
983
  main()