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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -19
app.py CHANGED
@@ -359,7 +359,7 @@ def show_weather_info(data):
359
  if precip_type == "λΉ„" or precip_type == "λΉ„/눈":
360
  weather_icon = "β˜”"
361
  elif precip_type == "눈":
362
- weather_icon = "❄"
363
  # PRECPT_TYPE이 'μ—†μŒ'이면 SKY_STTS 기반으둜 μ•„μ΄μ½˜ μ„€μ •
364
  else:
365
  if morning_six_data['SKY_STTS'] == "λ§‘μŒ":
@@ -380,9 +380,10 @@ def show_weather_info(data):
380
  if data['PRECPT_TYPE'] in ["λΉ„", "λΉ—λ°©μšΈ"]:
381
  weather_icon = "β˜”"
382
  elif data['PRECPT_TYPE'] == "눈":
383
- weather_icon = "❄"
384
  elif data['PRECPT_TYPE'] == "λΉ„/눈":
385
- weather_icon = "β˜”β„"
 
386
  else:
387
  # Find nearest forecast time when no current precipitation
388
  nearest_forecast = None
@@ -400,9 +401,10 @@ def show_weather_info(data):
400
  if nearest_forecast['PRECPT_TYPE'] in ["λΉ„", "λΉ—λ°©μšΈ"]:
401
  weather_icon = "β˜”"
402
  elif nearest_forecast['PRECPT_TYPE'] == "눈":
403
- weather_icon = "❄"
404
  elif nearest_forecast['PRECPT_TYPE'] == "λΉ„/눈":
405
- weather_icon = "β˜”β„"
 
406
  else:
407
  # Use SKY_STTS when no precipitation
408
  sky_status = nearest_forecast['SKY_STTS']
@@ -667,10 +669,10 @@ def show_temperature_graph(data):
667
  icon = "β˜”"
668
  description = "λΉ„"
669
  elif precip_type == "눈":
670
- icon = "❄"
671
- description = "눈"
672
  elif precip_type == "λΉ„/눈":
673
- icon = "β˜”β„"
674
  description = "λΉ„/눈"
675
  elif sky_status == "λ§‘μŒ":
676
  icon = "🌞"
@@ -890,38 +892,36 @@ def get_weather_forecast(forecast_data_str, current_time_str):
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
897
  st.session_state.weather_data = None
898
  st.session_state.api_failed = False
899
  st.session_state.scroll_visible = False
900
- st.session_state.weather_forecast = "" # weather_forecast μ΄ˆκΈ°ν™” μΆ”κ°€
901
 
902
- # ν˜„μž¬ μ‹œκ°„μ„ μ„œμšΈ μ‹œκ°„μœΌλ‘œ κ°€μ Έμ˜΅λ‹ˆλ‹€.
903
  current_time = datetime.utcnow() + timedelta(hours=9)
904
  current_timestamp = current_time.timestamp()
905
 
906
- # 데이터 μƒˆλ‘œκ³ μΉ¨ 체크
907
  if 'last_api_call' not in st.session_state:
908
  st.session_state.last_api_call = 0
909
 
910
  time_since_last_call = current_timestamp - st.session_state.last_api_call
 
911
 
912
- # μžλ™ μƒˆλ‘œκ³ μΉ¨μ„ μœ„ν•œ placeholder
913
  refresh_placeholder = st.empty()
914
 
915
  # λ„€νŠΈμ›Œν¬ μƒνƒœ 체크 및 데이터 κ°±μ‹ 
916
- if not st.session_state.weather_data or time_since_last_call >= 300:
917
  if check_network_status():
918
  try:
919
  new_data = get_weather_data()
920
  if new_data:
921
  st.session_state.weather_data = new_data
922
  st.session_state.last_api_call = current_timestamp
 
923
 
924
- # 배경색 μ—…λ°μ΄νŠΈ
925
  pm10_value = new_data['PM10']
926
  background_color = get_background_color(pm10_value)
927
  st.markdown(f"""
@@ -933,8 +933,13 @@ def main():
933
  """, unsafe_allow_html=True)
934
 
935
  st.rerun()
 
 
 
936
 
937
  except Exception as e:
 
 
938
  st.error(f"Failed to refresh data: {str(e)}")
939
  else:
940
  st.warning("ν˜„μž¬ λ„€νŠΈμ›Œν¬μ— λ¬Έμ œκ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. 데이터 ��신이 λΆˆκ°€λŠ₯ν•©λ‹ˆλ‹€.")
@@ -959,8 +964,7 @@ def main():
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:
966
  try:
@@ -972,12 +976,13 @@ def main():
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()
 
359
  if precip_type == "λΉ„" or precip_type == "λΉ„/눈":
360
  weather_icon = "β˜”"
361
  elif precip_type == "눈":
362
+ weather_icon = '<span style="color: white; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);">❄</span>'
363
  # PRECPT_TYPE이 'μ—†μŒ'이면 SKY_STTS 기반으둜 μ•„μ΄μ½˜ μ„€μ •
364
  else:
365
  if morning_six_data['SKY_STTS'] == "λ§‘μŒ":
 
380
  if data['PRECPT_TYPE'] in ["λΉ„", "λΉ—λ°©μšΈ"]:
381
  weather_icon = "β˜”"
382
  elif data['PRECPT_TYPE'] == "눈":
383
+ weather_icon = '<span style="color: white; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);">❄</span>'
384
  elif data['PRECPT_TYPE'] == "λΉ„/눈":
385
+ weather_icon = 'β˜”<span style="color: white; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);">❄</span>'
386
+
387
  else:
388
  # Find nearest forecast time when no current precipitation
389
  nearest_forecast = None
 
401
  if nearest_forecast['PRECPT_TYPE'] in ["λΉ„", "λΉ—λ°©μšΈ"]:
402
  weather_icon = "β˜”"
403
  elif nearest_forecast['PRECPT_TYPE'] == "눈":
404
+ weather_icon = '<span style="color: white; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);">❄</span>'
405
  elif nearest_forecast['PRECPT_TYPE'] == "λΉ„/눈":
406
+ weather_icon = 'β˜”<span style="color: white; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);">❄</span>'
407
+
408
  else:
409
  # Use SKY_STTS when no precipitation
410
  sky_status = nearest_forecast['SKY_STTS']
 
669
  icon = "β˜”"
670
  description = "λΉ„"
671
  elif precip_type == "눈":
672
+ icon = '<span style="color: white; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);">❄</span>'
673
+ description = "눈"
674
  elif precip_type == "λΉ„/눈":
675
+ icon = 'β˜”<span style="color: white; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);">❄</span>'
676
  description = "λΉ„/눈"
677
  elif sky_status == "λ§‘μŒ":
678
  icon = "🌞"
 
892
  def main():
893
  if 'api_status_time' not in st.session_state:
894
  st.session_state.api_status_time = None
895
+
896
  if 'current_section' not in st.session_state:
897
  st.session_state.current_section = 'weather'
898
  st.session_state.last_api_call = 0
899
  st.session_state.weather_data = None
900
  st.session_state.api_failed = False
901
  st.session_state.scroll_visible = False
902
+ st.session_state.weather_forecast = ""
903
 
 
904
  current_time = datetime.utcnow() + timedelta(hours=9)
905
  current_timestamp = current_time.timestamp()
906
 
 
907
  if 'last_api_call' not in st.session_state:
908
  st.session_state.last_api_call = 0
909
 
910
  time_since_last_call = current_timestamp - st.session_state.last_api_call
911
+ retry_interval = 60 if st.session_state.api_failed else 300 # API μ‹€νŒ¨μ‹œ 1λΆ„, μ •μƒμ‹œ 5λΆ„
912
 
 
913
  refresh_placeholder = st.empty()
914
 
915
  # λ„€νŠΈμ›Œν¬ μƒνƒœ 체크 및 데이터 κ°±μ‹ 
916
+ if not st.session_state.weather_data or time_since_last_call >= retry_interval:
917
  if check_network_status():
918
  try:
919
  new_data = get_weather_data()
920
  if new_data:
921
  st.session_state.weather_data = new_data
922
  st.session_state.last_api_call = current_timestamp
923
+ st.session_state.api_failed = False
924
 
 
925
  pm10_value = new_data['PM10']
926
  background_color = get_background_color(pm10_value)
927
  st.markdown(f"""
 
933
  """, unsafe_allow_html=True)
934
 
935
  st.rerun()
936
+ else:
937
+ st.session_state.api_failed = True
938
+ st.session_state.api_status_time = current_time
939
 
940
  except Exception as e:
941
+ st.session_state.api_failed = True
942
+ st.session_state.api_status_time = current_time
943
  st.error(f"Failed to refresh data: {str(e)}")
944
  else:
945
  st.warning("ν˜„μž¬ λ„€νŠΈμ›Œν¬μ— λ¬Έμ œκ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. 데이터 ��신이 λΆˆκ°€λŠ₯ν•©λ‹ˆλ‹€.")
 
964
 
965
  # μžλ™ μƒˆλ‘œκ³ μΉ¨μ„ μœ„ν•œ 타이머
966
  with refresh_placeholder:
967
+ if time_since_last_call >= retry_interval:
 
968
  network_ok = check_network_status()
969
  if network_ok:
970
  try:
 
976
  st.rerun()
977
  else:
978
  st.session_state.api_failed = True
979
+ st.session_state.api_status_time = current_time
980
  except:
981
  st.session_state.api_failed = True
982
+ st.session_state.api_status_time = current_time
983
 
984
+ time.sleep(60)
985
  st.rerun()
986
 
 
987
  if __name__ == "__main__":
988
  main()