Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
| 526 |
-
st.session_state.
|
|
|
|
| 527 |
else:
|
| 528 |
status_color = "#FF0000"
|
| 529 |
-
if st.session_state.
|
| 530 |
-
st.session_state.
|
| 531 |
-
|
| 532 |
-
status_text = f"API μλ΅ μμ({
|
| 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
|
| 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 |
-
|
|
|
|
|
|
|
| 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()
|