Spaces:
Running
Running
JAMESPARK3
commited on
Update app.py
Browse files
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 = ""
|
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 >=
|
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 >=
|
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)
|
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()
|