no message
This commit is contained in:
@ -8,7 +8,6 @@ app = Flask(__name__)
|
||||
DB_PATH = '/data/weather.sqlite'
|
||||
DOMAIN = os.getenv('DOMAIN', 'http://localhost:5000')
|
||||
|
||||
# 환경변수 FLASK_DEBUG를 받아서 '1'일 때만 True, 아니면 False로 처리 (기본 False)
|
||||
debug_env = os.getenv('FLASK_DEBUG', '0')
|
||||
DEBUG_MODE = debug_env == '1'
|
||||
|
||||
@ -28,10 +27,11 @@ def get_rain_data(date):
|
||||
|
||||
@app.route('/webhook', methods=['POST'])
|
||||
def webhook():
|
||||
today = datetime.today().strftime('%Y%m%d')
|
||||
response_text = ""
|
||||
|
||||
try:
|
||||
data = request.get_json(silent=True) # 비어있어도 None 반환, 예외 안남
|
||||
# 필요시 data['userRequest']['utterance'] 사용 가능
|
||||
today = datetime.today().strftime('%Y%m%d')
|
||||
|
||||
time_rain_list, total_rainfall = get_rain_data(today)
|
||||
|
||||
if not time_rain_list:
|
||||
@ -45,9 +45,6 @@ def webhook():
|
||||
lines.append(f"\n영업시간 내 총 강수량은 {total_rainfall:.1f}mm 입니다.")
|
||||
response_text = '\n'.join(lines)
|
||||
|
||||
except Exception as e:
|
||||
response_text = f"데이터 조회 중 오류가 발생했습니다: {e}"
|
||||
|
||||
image_filename = f"weather_capture_{today}.png"
|
||||
image_path = f"/data/{image_filename}"
|
||||
|
||||
@ -73,5 +70,18 @@ def webhook():
|
||||
}
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
# 에러 발생 시 카카오 챗봇이 받을 수 있는 기본 메시지 반환
|
||||
return jsonify({
|
||||
"version": "2.0",
|
||||
"template": {
|
||||
"outputs": [{
|
||||
"simpleText": {
|
||||
"text": f"서버 오류가 발생했습니다: {str(e)}"
|
||||
}
|
||||
}]
|
||||
}
|
||||
})
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5000, debug=DEBUG_MODE)
|
||||
|
||||
Reference in New Issue
Block a user