Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -216,7 +216,7 @@ def get_current_sky_status(data):
|
|
| 216 |
forecast_data = data['FCST24HOURS']['FCST24HOURS']
|
| 217 |
if not isinstance(forecast_data, list):
|
| 218 |
forecast_data = [forecast_data]
|
| 219 |
-
|
| 220 |
closest_forecast = None
|
| 221 |
min_time_diff = float('inf')
|
| 222 |
|
|
@@ -300,34 +300,44 @@ def show_weather_info(data):
|
|
| 300 |
except:
|
| 301 |
temp = "μ 보μμ"
|
| 302 |
|
| 303 |
-
#
|
| 304 |
-
|
|
|
|
|
|
|
| 305 |
forecast_data = data['FCST24HOURS']['FCST24HOURS']
|
| 306 |
if not isinstance(forecast_data, list):
|
| 307 |
forecast_data = [forecast_data]
|
| 308 |
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
|
|
|
|
|
|
|
|
|
| 313 |
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
|
| 332 |
# νλ©΄μ νμ
|
| 333 |
weather_icon = ""
|
|
@@ -365,7 +375,7 @@ def show_weather_info(data):
|
|
| 365 |
# Use SKY_STTS when no precipitation
|
| 366 |
sky_status = nearest_forecast['SKY_STTS']
|
| 367 |
if sky_status == "λ§μ":
|
| 368 |
-
weather_icon = "
|
| 369 |
elif sky_status in ["ꡬλ¦", "ꡬλ¦λ§μ"]:
|
| 370 |
weather_icon = "β
"
|
| 371 |
elif sky_status == "νλ¦Ό":
|
|
@@ -420,25 +430,31 @@ def show_temperature_graph(data):
|
|
| 420 |
|
| 421 |
# Sort forecast data by FCST_DT to ensure correct time ordering
|
| 422 |
forecast_data = sorted(forecast_data, key=lambda x: x['FCST_DT'])
|
| 423 |
-
|
| 424 |
# νμ¬ μκ° κΈ°μ€μΌλ‘ μ ν¨ν μ보 λ°μ΄ν°λ§ νν°λ§
|
| 425 |
-
current_time = datetime.utcnow() + timedelta(hours=9)
|
| 426 |
-
|
|
|
|
| 427 |
|
| 428 |
-
# νμ¬ μκ° μ΄νμ μ보 λ°μ΄ν°
|
| 429 |
-
valid_forecast_data = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
|
| 431 |
# μ ν¨ν λ°μ΄ν°κ° μμΌλ©΄ μ 체 λ°μ΄ν° μ¬μ©
|
| 432 |
if not valid_forecast_data:
|
| 433 |
valid_forecast_data = forecast_data
|
| 434 |
-
|
| 435 |
-
times = []
|
| 436 |
-
temps = []
|
| 437 |
-
weather_icons = []
|
| 438 |
-
weather_descriptions = []
|
| 439 |
-
date_changes = []
|
| 440 |
|
| 441 |
-
#
|
|
|
|
|
|
|
|
|
|
| 442 |
time_differences = []
|
| 443 |
for fcst in valid_forecast_data:
|
| 444 |
forecast_time = datetime.strptime(fcst['FCST_DT'], '%Y%m%d%H%M')
|
|
@@ -450,6 +466,12 @@ def show_temperature_graph(data):
|
|
| 450 |
# Reorder forecast data to start from current time
|
| 451 |
valid_forecast_data = valid_forecast_data[current_index:] + valid_forecast_data[:current_index]
|
| 452 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
for i, forecast in enumerate(valid_forecast_data):
|
| 454 |
time_str = forecast['FCST_DT']
|
| 455 |
date = time_str[6:8]
|
|
@@ -473,7 +495,7 @@ def show_temperature_graph(data):
|
|
| 473 |
icon = "ββ"
|
| 474 |
description = "λΉ/λ"
|
| 475 |
elif sky_status == "λ§μ":
|
| 476 |
-
icon = "
|
| 477 |
description = "λ§μ"
|
| 478 |
elif sky_status in ["ꡬλ¦", "ꡬλ¦λ§μ"]:
|
| 479 |
icon = "β
"
|
|
@@ -512,10 +534,7 @@ def show_temperature_graph(data):
|
|
| 512 |
annotation_position="top left"
|
| 513 |
)
|
| 514 |
|
| 515 |
-
#
|
| 516 |
-
current_time = datetime.utcnow() + timedelta(hours=9)
|
| 517 |
-
|
| 518 |
-
# λ
Ήμ μΈλ‘μ μΆκ° λ° "νμ¬" ν
μ€νΈ νμ - μ΄μ νμ 첫 λ²μ§Έ λ°μ΄ν° ν¬μΈνΈμ νμ
|
| 519 |
fig.add_vline(x=times[0], line_width=2, line_dash="dash", line_color="green")
|
| 520 |
fig.add_annotation(
|
| 521 |
x=times[0],
|
|
@@ -541,6 +560,8 @@ def show_temperature_graph(data):
|
|
| 541 |
|
| 542 |
# μ€λκ³Ό λ΄μΌ, μ€μ κ³Ό μ€ν ν
μ€νΈλ ν΄λΉ μκ°λμ λ°μ΄ν°κ° μμ λλ§ νμ
|
| 543 |
time_set = set(times)
|
|
|
|
|
|
|
| 544 |
|
| 545 |
if '11μ' in time_set:
|
| 546 |
fig.add_annotation(x='11μ', y=max(temps) + 4, text="μ€μ ", showarrow=False, font=dict(size=24))
|
|
@@ -548,11 +569,18 @@ def show_temperature_graph(data):
|
|
| 548 |
if '13μ' in time_set:
|
| 549 |
fig.add_annotation(x='13μ', y=max(temps) + 4, text="μ€ν", showarrow=False, font=dict(size=24))
|
| 550 |
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 556 |
|
| 557 |
fig.update_traces(
|
| 558 |
line_color='#FF6B6B',
|
|
@@ -610,11 +638,11 @@ def show_temperature_graph(data):
|
|
| 610 |
yaxis=dict(
|
| 611 |
tickfont=dict(size=14),
|
| 612 |
gridcolor='rgba(0,0,0,0.1)',
|
| 613 |
-
showticklabels=True,
|
| 614 |
-
tickformat='d',
|
| 615 |
-
ticksuffix='Β°C',
|
| 616 |
-
automargin=True,
|
| 617 |
-
rangemode='tozero'
|
| 618 |
)
|
| 619 |
)
|
| 620 |
|
|
|
|
| 216 |
forecast_data = data['FCST24HOURS']['FCST24HOURS']
|
| 217 |
if not isinstance(forecast_data, list):
|
| 218 |
forecast_data = [forecast_data]
|
| 219 |
+
|
| 220 |
closest_forecast = None
|
| 221 |
min_time_diff = float('inf')
|
| 222 |
|
|
|
|
| 300 |
except:
|
| 301 |
temp = "μ 보μμ"
|
| 302 |
|
| 303 |
+
# νμ¬ μκ° κΈ°μ€μΌλ‘ κ°μ₯ κ°κΉμ΄ 06μ λ°μ΄ν° μ°ΎκΈ°
|
| 304 |
+
morning_six_data = None
|
| 305 |
+
current_time = datetime.utcnow() + timedelta(hours=9) # KST
|
| 306 |
+
|
| 307 |
forecast_data = data['FCST24HOURS']['FCST24HOURS']
|
| 308 |
if not isinstance(forecast_data, list):
|
| 309 |
forecast_data = [forecast_data]
|
| 310 |
|
| 311 |
+
for fcst in forecast_data:
|
| 312 |
+
fcst_hour = int(fcst['FCST_DT'][8:10]) # HH
|
| 313 |
+
if fcst_hour == 6:
|
| 314 |
+
fcst_datetime = datetime.strptime(fcst['FCST_DT'], '%Y%m%d%H%M')
|
| 315 |
+
if fcst_datetime > current_time:
|
| 316 |
+
morning_six_data = fcst
|
| 317 |
+
break
|
| 318 |
|
| 319 |
+
# 06μ λ μ¨ μ 보 μ€λΉ
|
| 320 |
+
tomorrow_morning_weather = "μμ"
|
| 321 |
+
if morning_six_data:
|
| 322 |
+
tomorrow_temp = morning_six_data['TEMP']
|
| 323 |
+
weather_icon = ""
|
| 324 |
+
|
| 325 |
+
# PRECPT_TYPE λ¨Όμ νμΈ
|
| 326 |
+
precip_type = morning_six_data['PRECPT_TYPE']
|
| 327 |
+
if precip_type == "λΉ" or precip_type == "λΉ/λ":
|
| 328 |
+
weather_icon = "β"
|
| 329 |
+
elif precip_type == "λ":
|
| 330 |
+
weather_icon = "β"
|
| 331 |
+
# PRECPT_TYPEμ΄ 'μμ'μ΄λ©΄ SKY_STTS κΈ°λ°μΌλ‘ μμ΄μ½ μ€μ
|
| 332 |
+
else:
|
| 333 |
+
if morning_six_data['SKY_STTS'] == "λ§μ":
|
| 334 |
+
weather_icon = "π"
|
| 335 |
+
elif morning_six_data['SKY_STTS'] in ["ꡬλ¦", "ꡬλ¦λ§μ"]:
|
| 336 |
+
weather_icon = "β
"
|
| 337 |
+
elif morning_six_data['SKY_STTS'] == "νλ¦Ό":
|
| 338 |
+
weather_icon = "βοΈ"
|
| 339 |
+
|
| 340 |
+
tomorrow_morning_weather = f"{tomorrow_temp}Β°C {weather_icon}"
|
| 341 |
|
| 342 |
# νλ©΄μ νμ
|
| 343 |
weather_icon = ""
|
|
|
|
| 375 |
# Use SKY_STTS when no precipitation
|
| 376 |
sky_status = nearest_forecast['SKY_STTS']
|
| 377 |
if sky_status == "λ§μ":
|
| 378 |
+
weather_icon = "π"
|
| 379 |
elif sky_status in ["ꡬλ¦", "ꡬλ¦λ§μ"]:
|
| 380 |
weather_icon = "β
"
|
| 381 |
elif sky_status == "νλ¦Ό":
|
|
|
|
| 430 |
|
| 431 |
# Sort forecast data by FCST_DT to ensure correct time ordering
|
| 432 |
forecast_data = sorted(forecast_data, key=lambda x: x['FCST_DT'])
|
| 433 |
+
|
| 434 |
# νμ¬ μκ° κΈ°μ€μΌλ‘ μ ν¨ν μ보 λ°μ΄ν°λ§ νν°λ§
|
| 435 |
+
current_time = datetime.utcnow() + timedelta(hours=9) # KST
|
| 436 |
+
current_date = current_time.strftime('%Y%m%d')
|
| 437 |
+
next_date = (current_time + timedelta(days=1)).strftime('%Y%m%d')
|
| 438 |
|
| 439 |
+
# νμ¬ μκ° μ΄νμ μ보 λ°μ΄ν°μ λ€μ λ μ λ°μ΄ν° λͺ¨λ ν¬ν¨
|
| 440 |
+
valid_forecast_data = []
|
| 441 |
+
for fcst in forecast_data:
|
| 442 |
+
fcst_date = fcst['FCST_DT'][:8] # YYYYMMDD
|
| 443 |
+
fcst_hour = int(fcst['FCST_DT'][8:10]) # HH
|
| 444 |
+
current_hour = current_time.hour
|
| 445 |
+
|
| 446 |
+
# νμ¬ λ μ§μ νμ¬ μκ° μ΄ν λ°μ΄ν° λλ λ€μ λ μ λ°μ΄ν°
|
| 447 |
+
if (fcst_date == current_date and fcst_hour >= current_hour) or fcst_date == next_date:
|
| 448 |
+
valid_forecast_data.append(fcst)
|
| 449 |
|
| 450 |
# μ ν¨ν λ°μ΄ν°κ° μμΌλ©΄ μ 체 λ°μ΄ν° μ¬μ©
|
| 451 |
if not valid_forecast_data:
|
| 452 |
valid_forecast_data = forecast_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
|
| 454 |
+
# νμ¬ μκ°κ³Ό κ°μ₯ κ°κΉμ΄ μ보 μκ° μ°ΎκΈ°
|
| 455 |
+
current_time = datetime.utcnow() + timedelta(hours=9)
|
| 456 |
+
|
| 457 |
+
# λ
Ήμ μΈλ‘μ μΆκ° λ° "νμ¬" ν
μ€νΈ νμ - μ΄μ νμ 첫 λ²μ§Έ λ°μ΄ν° ν¬μΈνΈμ νμ
|
| 458 |
time_differences = []
|
| 459 |
for fcst in valid_forecast_data:
|
| 460 |
forecast_time = datetime.strptime(fcst['FCST_DT'], '%Y%m%d%H%M')
|
|
|
|
| 466 |
# Reorder forecast data to start from current time
|
| 467 |
valid_forecast_data = valid_forecast_data[current_index:] + valid_forecast_data[:current_index]
|
| 468 |
|
| 469 |
+
times = []
|
| 470 |
+
temps = []
|
| 471 |
+
weather_icons = []
|
| 472 |
+
weather_descriptions = []
|
| 473 |
+
date_changes = []
|
| 474 |
+
|
| 475 |
for i, forecast in enumerate(valid_forecast_data):
|
| 476 |
time_str = forecast['FCST_DT']
|
| 477 |
date = time_str[6:8]
|
|
|
|
| 495 |
icon = "ββ"
|
| 496 |
description = "λΉ/λ"
|
| 497 |
elif sky_status == "λ§μ":
|
| 498 |
+
icon = "π"
|
| 499 |
description = "λ§μ"
|
| 500 |
elif sky_status in ["ꡬλ¦", "ꡬλ¦λ§μ"]:
|
| 501 |
icon = "β
"
|
|
|
|
| 534 |
annotation_position="top left"
|
| 535 |
)
|
| 536 |
|
| 537 |
+
# λ
Ήμ μΈλ‘μ μΆκ° λ° "νμ¬" ν
μ€νΈ νμ
|
|
|
|
|
|
|
|
|
|
| 538 |
fig.add_vline(x=times[0], line_width=2, line_dash="dash", line_color="green")
|
| 539 |
fig.add_annotation(
|
| 540 |
x=times[0],
|
|
|
|
| 560 |
|
| 561 |
# μ€λκ³Ό λ΄μΌ, μ€μ κ³Ό μ€ν ν
μ€νΈλ ν΄λΉ μκ°λμ λ°μ΄ν°κ° μμ λλ§ νμ
|
| 562 |
time_set = set(times)
|
| 563 |
+
current_date = datetime.utcnow() + timedelta(hours=9) # KST
|
| 564 |
+
current_hour = current_date.hour
|
| 565 |
|
| 566 |
if '11μ' in time_set:
|
| 567 |
fig.add_annotation(x='11μ', y=max(temps) + 4, text="μ€μ ", showarrow=False, font=dict(size=24))
|
|
|
|
| 569 |
if '13μ' in time_set:
|
| 570 |
fig.add_annotation(x='13μ', y=max(temps) + 4, text="μ€ν", showarrow=False, font=dict(size=24))
|
| 571 |
|
| 572 |
+
# μκ° μμλλ‘ μ λ ¬λ λ°μ΄ν°λΌκ³ κ°μ
|
| 573 |
+
for i, time in enumerate(times):
|
| 574 |
+
hour = int(time.replace('μ', ''))
|
| 575 |
+
|
| 576 |
+
# νμ¬ μκ°μ΄ 23μμ΄κ³ , times[0]μ΄ 00μλΌλ©΄ 첫 λ²μ§Έ 23μκ° μ€λ 23μ
|
| 577 |
+
if hour == 23 and times[0] == '00μ':
|
| 578 |
+
if i == 0: # 첫 λ²μ§Έ 23μ (μ€λ 23μ)
|
| 579 |
+
fig.add_annotation(x=time, y=max(temps) + 4, text="μ€λ", showarrow=False, font=dict(size=24))
|
| 580 |
+
|
| 581 |
+
# 01μλ λ€μ λ μ΄λ―λ‘ "λ΄μΌ" νμ (00μ λ€μμ μ€λ 01μ)
|
| 582 |
+
if hour == 1 and i > 0 and times[i-1] == '00μ':
|
| 583 |
+
fig.add_annotation(x=time, y=max(temps) + 4, text="λ΄μΌ", showarrow=False, font=dict(size=24))
|
| 584 |
|
| 585 |
fig.update_traces(
|
| 586 |
line_color='#FF6B6B',
|
|
|
|
| 638 |
yaxis=dict(
|
| 639 |
tickfont=dict(size=14),
|
| 640 |
gridcolor='rgba(0,0,0,0.1)',
|
| 641 |
+
showticklabels=True,
|
| 642 |
+
tickformat='d',
|
| 643 |
+
ticksuffix='Β°C',
|
| 644 |
+
automargin=True,
|
| 645 |
+
rangemode='tozero'
|
| 646 |
)
|
| 647 |
)
|
| 648 |
|