webhook 응답테스트용 파일
This commit is contained in:
@ -4,12 +4,10 @@ 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 읽기, 없으면 기본값 지정 (로컬 테스트용)
|
|
||||||
DOMAIN = os.getenv('DOMAIN', 'http://localhost:5000')
|
DOMAIN = os.getenv('DOMAIN', 'http://localhost:5000')
|
||||||
|
|
||||||
|
|
||||||
def get_rain_data(date):
|
def get_rain_data(date):
|
||||||
conn = sqlite3.connect(DB_PATH)
|
conn = sqlite3.connect(DB_PATH)
|
||||||
curs = conn.cursor()
|
curs = conn.cursor()
|
||||||
@ -24,11 +22,19 @@ 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)
|
||||||
|
|
||||||
@ -45,18 +51,12 @@ def webhook():
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
response_text = f"데이터 조회 중 오류가 발생했습니다: {e}"
|
response_text = f"데이터 조회 중 오류가 발생했습니다: {e}"
|
||||||
|
else:
|
||||||
|
response_text = "원하시는 정보를 다시 말씀해 주세요. 예: '오늘 비 와요?', '강수량 알려줘' 등"
|
||||||
|
|
||||||
image_filename = f"weather_capture_{today}.png"
|
outputs = [{"simpleText": {"text": response_text}}]
|
||||||
image_path = f"/data/{image_filename}"
|
|
||||||
|
|
||||||
outputs = [{
|
if os.path.isfile(image_path) and ("날씨" in utterance or "강수" in utterance or "비" in utterance):
|
||||||
"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,5 +71,6 @@ 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)
|
||||||
|
|||||||
Reference in New Issue
Block a user