JAMESPARK3 commited on
Commit
f880c9e
Β·
verified Β·
1 Parent(s): cb75c90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -52
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
- # 내일 μ•„μΉ¨ 6μ‹œ 예보 μ°ΎκΈ°
304
- tomorrow_morning_weather = "μ—†μŒ"
 
 
305
  forecast_data = data['FCST24HOURS']['FCST24HOURS']
306
  if not isinstance(forecast_data, list):
307
  forecast_data = [forecast_data]
308
 
309
- # ν˜„μž¬ μ‹œκ°„ κΈ°μ€€μœΌλ‘œ 내일 λ‚ μ§œ 계산
310
- current_time = datetime.utcnow() + timedelta(hours=9)
311
- tomorrow = current_time + timedelta(days=1)
312
- tomorrow_date = tomorrow.strftime('%Y%m%d')
 
 
 
313
 
314
- for forecast in forecast_data:
315
- # λ‚ μ§œμ™€ μ‹œκ°„μ΄ λͺ¨λ‘ μΌμΉ˜ν•˜λŠ”μ§€ 확인
316
- if forecast['FCST_DT'][:8] == tomorrow_date and forecast['FCST_DT'][8:10] == '06':
317
- tomorrow_temp = forecast['TEMP']
318
- precip_type = forecast['PRECPT_TYPE']
319
-
320
- # κ°•μˆ˜ νƒ€μž…μ— λ”°λ₯Έ μ•„μ΄μ½˜
321
- weather_icon = ""
322
- if precip_type == "λΉ„":
323
- weather_icon = "β˜”"
324
- elif precip_type == "눈":
325
- weather_icon = "❄"
326
- elif precip_type == "λΉ„/눈":
327
- weather_icon = "β˜”β„"
328
-
329
- tomorrow_morning_weather = f"{tomorrow_temp}Β°C {weather_icon}"
330
- break
 
 
 
 
 
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
- current_time_str = current_time.strftime('%Y%m%d%H%M')
 
427
 
428
- # ν˜„μž¬ μ‹œκ°„ μ΄ν›„μ˜ 예보 λ°μ΄ν„°λ§Œ 필터링
429
- valid_forecast_data = [fcst for fcst in forecast_data if fcst['FCST_DT'] >= current_time_str]
 
 
 
 
 
 
 
 
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
- # Find the index closest to current time
 
 
 
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
- if '23μ‹œ' in time_set:
552
- fig.add_annotation(x='23μ‹œ', y=max(temps) + 4, text="였늘", showarrow=False, font=dict(size=24))
553
-
554
- if '01μ‹œ' in time_set:
555
- fig.add_annotation(x='01μ‹œ', y=max(temps) + 4, text="내일", showarrow=False, font=dict(size=24))
 
 
 
 
 
 
 
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, # yμΆ• λ ˆμ΄λΈ” ν‘œμ‹œ
614
- tickformat='d', # μ •μˆ˜ ν˜•μ‹μœΌλ‘œ ν‘œμ‹œ
615
- ticksuffix='Β°C', # μ˜¨λ„ λ‹¨μœ„ μΆ”κ°€
616
- automargin=True, # yμΆ• μžλ™ λ§ˆμ§„ μ„€μ •
617
- rangemode='tozero' # yμΆ• λ²”μœ„ μ„€μ •
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