Seungmi

python 추가

Showing 1 changed file with 37 additions and 10 deletions
......@@ -11,9 +11,10 @@ const bodyParser = require('body-parser');
var app = express();
const { info } = require('console');
var PythonShell = require('python-shell');
var { PythonShell } = require('python-shell');
var pyshell = new PythonShell('weather_chat.py');
var options = {
let options = {
mode: 'text',
pythonPath: '',
pythonOptions: ['-u'],
......@@ -41,11 +42,8 @@ app.post('/hook', function (req, res) {
else if(eventObj.message.text == "이용방법") {
chatUse(eventObj.replyToken);
}
else if(eventObj.message.text == "오늘의 날씨는") {
PythonShell.run('weather_chat.py', options, function(err, results) {
if(err) throw err;
console.log('results: %j', results);
});
else if(eventObj.message.text == "오늘의 날씨는?") {
chatWeather(eventObj.replyToken);
}
else {
chatWrong(eventObj.replyToken);
......@@ -66,7 +64,7 @@ function chatInfo(replyToken){
"messages":[
{
"type":"text",
"text":"서울 지역의 날씨와 기온에 따른 옷차림새를 추천해줍니다."
"text":"서울 지역의 오늘의 날씨와 기온에 따른 옷차림새를 추천해줍니다."
}
]
}
......@@ -87,7 +85,36 @@ function chatUse(replyToken){
"messages":[
{
"type":"text",
"text":"오늘의 날씨는? 을 똑같이\n 입력해주시면 작동합니다."
"text":"오늘의 날씨는? 을 똑같이\n입력해주시면 작동합니다."
}
]
}
},(error, response, body) => {
console.log(body)
});
}
function chatWeather(replyToken){
var PM = " ";
pyshell.send('request')
pyshell.on('message', function(data){
console.log(data);
PM = data;
});
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken":replyToken,
"messages":[
{
"type":"text",
"text": PM
}
]
}
......@@ -108,7 +135,7 @@ function chatWrong(replyToken){
"messages":[
{
"type":"text",
"text":"잘못된 입력입니다.\n '이용방법' 혹은 '오늘의 날씨는?'을 입력해주세요."
"text":"잘못된 입력입니다.\n'설명', '이용방법', '오늘의 날씨는?' \n중 하나를 입력해주세요."
}
]
}
......