From 62de9ff3d3def38f939332fa64c028b86f325dac Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Fri, 16 Aug 2024 00:34:22 +0900 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E5=A0=B1=E3=81=A8=E6=9C=80?= =?UTF-8?q?=E7=B5=82=E5=A0=B1=E3=81=AE=E3=81=BF=E3=82=92=E3=83=8E=E3=83=BC?= =?UTF-8?q?=E3=83=88=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- earthquake_bot.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/earthquake_bot.py b/earthquake_bot.py index 1aa5b0c..8d91103 100644 --- a/earthquake_bot.py +++ b/earthquake_bot.py @@ -34,15 +34,19 @@ class Bot(): def format_earthquake_info(self, data): if data['type'] == 'eew': event_time = datetime.fromtimestamp(int(data['time']) / 1000).strftime("%Y年%m月%d日 %H時%M分%S秒") - if data['report'] == 'final': - report_number = '最終' + if data["report"] == '1' or data['report'] == 'final': + if data['report'] == 'final': + report_number = '最終' + else: + report_number = '第' + data['report'] + + intensity = data['intensity'] + epicenter = data['epicenter'] + epicenter_depth = data['depth'] + magnitude = data['magnitude'] + result = {"result": 0, "detail": f"震源地 {epicenter} 予想震度 {intensity}\nマグニチュード {magnitude} 震源の深さ {epicenter_depth}\n緊急地震速報 {report_number}報\n時刻 | {event_time}"} else: - report_number = '第' + data['report'] - intensity = data['intensity'] - epicenter = data['epicenter'] - epicenter_depth = data['depth'] - magnitude = data['magnitude'] - result = {"result": 0, "detail": f"震源地 {epicenter} 予想震度 {intensity}\nマグニチュード {magnitude} 震源の深さ {epicenter_depth}\n緊急地震速報 {report_number}報\n時刻 | {event_time}"} + result = {"result": 1, "detail": "not_1st_or_final_report"} elif data['type'] == 'pga_alert_cancel': print(data) result = {"result": 0, "detail": f"誤報を検出。一つ前のノートは誤報です。"} @@ -83,6 +87,9 @@ def receive_earthquake_data(): elif info["detail"] == "intensity_report_detected": print(f"{str(current_time)} intensity_report のため、無視されました。") return jsonify({"status": "passed", "message": "intensity_report"}), 500 + elif info["detail"] == "not_1st_or_final_report": + print(f"{str(current_time)} 第1報 または 最終報 以外 のため、無視されました。") + return jsonify({"status": "passed", "message": "not_1st_or_final_report"}), 500 else: print(f"{str(current_time)} 不明なデータ のため、無視されました。\njsonの内容") print(earthquake_data)