From 4d31353a798f814b510f23a3c5f6b2b0bf81ebef Mon Sep 17 00:00:00 2001 From: KWON Date: Fri, 27 Jun 2025 15:07:36 +0900 Subject: [PATCH] =?UTF-8?q?=EC=8A=A4=ED=83=80=EC=9D=BC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95,=20=EC=9D=91=EB=8B=B5=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=8B=9C=20=EC=9E=AC=EC=8B=9C=EB=8F=84=201=ED=9A=8C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/weather.py | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/data/weather.py b/data/weather.py index 5f07a3f..fc25c76 100644 --- a/data/weather.py +++ b/data/weather.py @@ -18,7 +18,7 @@ def parse_precip(value): else: return 0.0 -def get_precipitation_summary(): +def get_precipitation_summary(retry=True): url = "http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst" params = { @@ -37,9 +37,29 @@ def get_precipitation_summary(): try: data = response.json() total_rainfall = 0.0 - lines = [f'

[시간대별 강수량]

'] - lines.append(f'') - lines.append(f'') + + lines = [ + '', + '
', + '

[시간대별 강수량]

', + '
시간강수량
', + '' + ] for item in data['response']['body']['items']['item']: if item['category'] == 'PCP' and item['fcstDate'] == TODAY: @@ -47,17 +67,20 @@ def get_precipitation_summary(): if 900 < int(time) < 2300: mm = parse_precip(item['fcstValue']) time_str = f"{time[:2]}:{time[2:]}" # '11:00' - lines.append(f'') + lines.append(f'') total_rainfall += mm - - lines.append("
시간강수량
{time_str}{mm}mm
{time_str}{mm}mm
") - lines.append(f"

영업시간 중 총 예상 강수량: {total_rainfall:.1f}mm

") + lines.append('') + lines.append(f'

영업시간 중 총 예상 강수량: {total_rainfall:.1f}mm

') return ''.join(lines) except json.decoder.JSONDecodeError: - return "⚠️ 응답이 JSON 형식이 아닙니다." + if retry: + print("⚠️ JSON 디코드 오류 발생, 재시도 중...") + return get_precipitation_summary(retry=False) + else: + return "⚠️ 응답이 JSON 형식이 아닙니다." # 테스트용 if __name__ == "__main__":