webhook 서버 디버깅용
This commit is contained in:
@ -17,4 +17,5 @@ services:
|
|||||||
- 5151:5000
|
- 5151:5000
|
||||||
environment:
|
environment:
|
||||||
- DOMAIN=https://webhook.firstgarden.co.kr
|
- DOMAIN=https://webhook.firstgarden.co.kr
|
||||||
|
- FLASK_DEBUG=1 #디버그 활성화
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
@ -4,9 +4,13 @@ import sqlite3
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
DB_PATH = '/data/weather.sqlite'
|
DB_PATH = '/data/weather.sqlite'
|
||||||
DOMAIN = os.getenv('DOMAIN', 'http://localhost:5000')
|
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'
|
||||||
|
|
||||||
def get_rain_data(date):
|
def get_rain_data(date):
|
||||||
conn = sqlite3.connect(DB_PATH)
|
conn = sqlite3.connect(DB_PATH)
|
||||||
@ -22,41 +26,39 @@ def get_rain_data(date):
|
|||||||
conn.close()
|
conn.close()
|
||||||
return time_rain_list, total_rainfall
|
return time_rain_list, total_rainfall
|
||||||
|
|
||||||
|
|
||||||
@app.route('/webhook', methods=['POST'])
|
@app.route('/webhook', methods=['POST'])
|
||||||
def webhook():
|
def webhook():
|
||||||
data = request.json
|
|
||||||
utterance = data.get("userRequest", {}).get("utterance", "").strip()
|
|
||||||
today = datetime.today().strftime('%Y%m%d')
|
today = datetime.today().strftime('%Y%m%d')
|
||||||
image_filename = f"weather_capture_{today}.png"
|
|
||||||
image_path = f"/data/{image_filename}"
|
|
||||||
image_url = f"{DOMAIN}/data/{image_filename}"
|
|
||||||
|
|
||||||
response_text = ""
|
response_text = ""
|
||||||
|
|
||||||
if "날씨" in utterance or "강수" in utterance or "비" in utterance:
|
try:
|
||||||
try:
|
time_rain_list, total_rainfall = get_rain_data(today)
|
||||||
time_rain_list, total_rainfall = get_rain_data(today)
|
|
||||||
|
|
||||||
if not time_rain_list:
|
if not time_rain_list:
|
||||||
response_text = f"{today} 날짜의 강수량 데이터가 없습니다."
|
response_text = f"{today} 날짜의 강수량 데이터가 없습니다."
|
||||||
else:
|
else:
|
||||||
lines = []
|
lines = []
|
||||||
for time_str, rain in time_rain_list:
|
for time_str, rain in time_rain_list:
|
||||||
rain_display = f"{rain}mm" if rain > 0 else "강수 없음"
|
rain_display = f"{rain}mm" if rain > 0 else "강수 없음"
|
||||||
lines.append(f"{time_str} → {rain_display}")
|
lines.append(f"{time_str} → {rain_display}")
|
||||||
|
|
||||||
lines.append(f"\n영업시간 내 총 강수량은 {total_rainfall:.1f}mm 입니다.")
|
lines.append(f"\n영업시간 내 총 강수량은 {total_rainfall:.1f}mm 입니다.")
|
||||||
response_text = '\n'.join(lines)
|
response_text = '\n'.join(lines)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
response_text = f"데이터 조회 중 오류가 발생했습니다: {e}"
|
response_text = f"데이터 조회 중 오류가 발생했습니다: {e}"
|
||||||
else:
|
|
||||||
response_text = "원하시는 정보를 다시 말씀해 주세요. 예: '오늘 비 와요?', '강수량 알려줘' 등"
|
|
||||||
|
|
||||||
outputs = [{"simpleText": {"text": response_text}}]
|
image_filename = f"weather_capture_{today}.png"
|
||||||
|
image_path = f"/data/{image_filename}"
|
||||||
|
|
||||||
if os.path.isfile(image_path) and ("날씨" in utterance or "강수" in utterance or "비" in utterance):
|
outputs = [{
|
||||||
|
"simpleText": {
|
||||||
|
"text": response_text
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
|
||||||
|
if os.path.isfile(image_path):
|
||||||
|
image_url = f"{DOMAIN}/data/{image_filename}"
|
||||||
outputs.append({
|
outputs.append({
|
||||||
"image": {
|
"image": {
|
||||||
"imageUrl": image_url,
|
"imageUrl": image_url,
|
||||||
@ -71,6 +73,5 @@ def webhook():
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0', port=5000)
|
app.run(host='0.0.0.0', port=5000, debug=DEBUG_MODE)
|
||||||
|
|||||||
Reference in New Issue
Block a user