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'
| 시간 | 강수량 |
|---|
| 시간 | 강수량 |
|---|---|
| {time_str} | {mm}mm |
| {time_str} | {mm}mm |
영업시간 중 총 예상 강수량: {total_rainfall:.1f}mm
") + lines.append('영업시간 중 총 예상 강수량: {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__":