Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -152,8 +152,8 @@ st.markdown("""
|
|
| 152 |
.scroll-text {
|
| 153 |
display: inline-block;
|
| 154 |
white-space: nowrap;
|
| 155 |
-
animation: scrolling
|
| 156 |
-
font-size:
|
| 157 |
font-weight: bold;
|
| 158 |
color: #333;
|
| 159 |
position: relative;
|
|
@@ -483,6 +483,56 @@ def show_weather_info(data):
|
|
| 483 |
status_text = "API μ μ" if not st.session_state.api_failed else "API μλ΅ μμ"
|
| 484 |
st.markdown(f'<p style="color:{status_color}; font-size:20px; font-weight:bold;">{status_text}</p>', unsafe_allow_html=True)
|
| 485 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 486 |
|
| 487 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 488 |
|
|
@@ -798,13 +848,26 @@ def main():
|
|
| 798 |
|
| 799 |
# λ€νΈμν¬ μν μ²΄ν¬ λ° λ°μ΄ν° κ°±μ
|
| 800 |
if not st.session_state.weather_data or time_since_last_call >= 300:
|
| 801 |
-
if check_network_status():
|
| 802 |
try:
|
| 803 |
new_data = get_weather_data()
|
| 804 |
-
if new_data:
|
| 805 |
st.session_state.weather_data = new_data
|
| 806 |
st.session_state.last_api_call = current_timestamp
|
| 807 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 808 |
except Exception as e:
|
| 809 |
st.error(f"Failed to refresh data: {str(e)}")
|
| 810 |
else:
|
|
|
|
| 152 |
.scroll-text {
|
| 153 |
display: inline-block;
|
| 154 |
white-space: nowrap;
|
| 155 |
+
animation: scrolling 30s linear infinite;
|
| 156 |
+
font-size: 2.5em;
|
| 157 |
font-weight: bold;
|
| 158 |
color: #333;
|
| 159 |
position: relative;
|
|
|
|
| 483 |
status_text = "API μ μ" if not st.session_state.api_failed else "API μλ΅ μμ"
|
| 484 |
st.markdown(f'<p style="color:{status_color}; font-size:20px; font-weight:bold;">{status_text}</p>', unsafe_allow_html=True)
|
| 485 |
|
| 486 |
+
# forecast_data μ²λ¦¬
|
| 487 |
+
forecast_data = data['FCST24HOURS']['FCST24HOURS']
|
| 488 |
+
if not isinstance(forecast_data, list):
|
| 489 |
+
forecast_data = [forecast_data]
|
| 490 |
+
|
| 491 |
+
times = []
|
| 492 |
+
temps = []
|
| 493 |
+
weather_descriptions = []
|
| 494 |
+
|
| 495 |
+
for forecast in forecast_data:
|
| 496 |
+
times.append(forecast['FCST_DT'][8:10] + "μ")
|
| 497 |
+
temps.append(float(forecast['TEMP']))
|
| 498 |
+
|
| 499 |
+
sky_status = forecast['SKY_STTS']
|
| 500 |
+
precip_type = forecast['PRECPT_TYPE']
|
| 501 |
+
|
| 502 |
+
if precip_type == "λΉ":
|
| 503 |
+
description = "λΉ"
|
| 504 |
+
elif precip_type == "λ":
|
| 505 |
+
description = "λ"
|
| 506 |
+
elif precip_type == "λΉ/λ":
|
| 507 |
+
description = "λΉ/λ"
|
| 508 |
+
elif sky_status == "λ§μ":
|
| 509 |
+
description = "λ§μ"
|
| 510 |
+
elif sky_status in ["ꡬλ¦", "ꡬλ¦λ§μ"]:
|
| 511 |
+
description = "ꡬλ¦" if sky_status == "ꡬλ¦" else "ꡬλ¦λ§μ"
|
| 512 |
+
elif sky_status == "νλ¦Ό":
|
| 513 |
+
description = "νλ¦Ό"
|
| 514 |
+
else:
|
| 515 |
+
description = "μ 보μμ"
|
| 516 |
+
|
| 517 |
+
weather_descriptions.append(description)
|
| 518 |
+
|
| 519 |
+
# λ μ¨ μ보 μμ± λ° νμ
|
| 520 |
+
if 'weather_forecast' not in st.session_state:
|
| 521 |
+
forecast_data_str = "\n".join([
|
| 522 |
+
f"[{f['FCST_DT'][:4]}λ
{f['FCST_DT'][4:6]}μ {f['FCST_DT'][6:8]}μΌ {f['FCST_DT'][8:10]}μ] {temp}λ, {description}"
|
| 523 |
+
for f, time, temp, description in zip(forecast_data, times, temps, weather_descriptions)
|
| 524 |
+
])
|
| 525 |
+
|
| 526 |
+
current_time_str = current_time.strftime('%Hμ %MλΆ')
|
| 527 |
+
st.session_state.weather_forecast = get_weather_forecast(forecast_data_str, current_time_str)
|
| 528 |
+
|
| 529 |
+
# μ μ₯λ λ μ¨ μ보 νμ
|
| 530 |
+
st.markdown(f'''
|
| 531 |
+
<div class="scroll-container">
|
| 532 |
+
<div class="scroll-text">{st.session_state.weather_forecast}</div>
|
| 533 |
+
</div>
|
| 534 |
+
''', unsafe_allow_html=True)
|
| 535 |
+
|
| 536 |
|
| 537 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 538 |
|
|
|
|
| 848 |
|
| 849 |
# λ€νΈμν¬ μν μ²΄ν¬ λ° λ°μ΄ν° κ°±μ
|
| 850 |
if not st.session_state.weather_data or time_since_last_call >= 300:
|
| 851 |
+
if check_network_status():
|
| 852 |
try:
|
| 853 |
new_data = get_weather_data()
|
| 854 |
+
if new_data:
|
| 855 |
st.session_state.weather_data = new_data
|
| 856 |
st.session_state.last_api_call = current_timestamp
|
| 857 |
+
|
| 858 |
+
# λ°°κ²½μ μ
λ°μ΄νΈ
|
| 859 |
+
pm10_value = new_data['PM10']
|
| 860 |
+
background_color = get_background_color(pm10_value)
|
| 861 |
+
st.markdown(f"""
|
| 862 |
+
<style>
|
| 863 |
+
.stApp {{
|
| 864 |
+
background-color: {background_color};
|
| 865 |
+
}}
|
| 866 |
+
</style>
|
| 867 |
+
""", unsafe_allow_html=True)
|
| 868 |
+
|
| 869 |
+
st.rerun()
|
| 870 |
+
|
| 871 |
except Exception as e:
|
| 872 |
st.error(f"Failed to refresh data: {str(e)}")
|
| 873 |
else:
|