JAMESPARK3 commited on
Commit
1688a79
Β·
verified Β·
1 Parent(s): d9729f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -5
app.py CHANGED
@@ -152,8 +152,8 @@ st.markdown("""
152
  .scroll-text {
153
  display: inline-block;
154
  white-space: nowrap;
155
- animation: scrolling 60s linear infinite;
156
- font-size: 1.5em;
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(): # λ„€νŠΈμ›Œν¬κ°€ 정상인 경우만 API 호좜
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
- st.rerun() # νŽ˜μ΄μ§€ μƒˆλ‘œκ³ μΉ¨
 
 
 
 
 
 
 
 
 
 
 
 
 
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: