EC2 Default User

app.js demo

var end = false;
var count = 0;
n1 = '';
var directory = [['korean_food_final.txt','chinese_food_final.txt','japanese_food_final.txt','western_food_final.txt','ect_food_final.txt'],['meat.txt','fish.txt','ect.txt','\0','\0'],['spicy_food_final.txt','not_spicy_food_final.txt','\0','\0','\0'],['water.txt','dry.txt','\0','\0','\0'],['hot_food_final.txt','cold_food_final.txt','\0','\0','\0']];
var real_data = '';
var directory = [['food_division_txt_file/korean_food_final.txt','food_division_txt_file/chinese_food_final.txt','food_division_txt_file/japanese_food_final.txt','food_division_txt_file/western_food_final.txt','food_division_txt_file/etc_food_final.txt'],['food_division_txt_file/meat.txt','food_division_txt_file/fish.txt','food_division_txt_file/ect.txt','\0','\0'],['food_division_txt_file/spicy_food_final.txt','food_division_txt_file/not_spicy_food_final.txt','\0','\0','\0'],['food_division_txt_file/water.txt','food_division_txt_file/dry.txt','\0','\0','\0'],['food_division_txt_file/cold_food_final.txt','food_division_txt_file/hot_food_final.txt','\0','\0','\0']];
var save_file_name = ['fin_1.txt','fin_2.txt','fin_3.txt','fin.txt'];
var choosen = new Array();
var express = require('express');
......@@ -9,8 +9,8 @@ const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const TOKEN = 'Ur8nbk2bQAc9KavLSSJv0uzlKWCxCBnOJOKyqbRS1mMHWgJlEOPfb7v+X1DDEHocUmhU7KnPFN+KHt5S3SYd5QmF42aTeQpW2gDVTjyqty1Tn+p6QqEhI/uSz659PBHwczEYn0Plx+akfCNHDPJRpAdB04t89/1O/w1cDnyilFU='
const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt'
const PAPAGO_ID = '1Z83W3lUGLqnNbrDAk8A'
const PAPAGO_SECRET = 'ST7ElRPFPP'
const PAPAGO_ID = '7S7IVuHMvSgjpygsJ0uN'
const PAPAGO_SECRET = 'WpWAr55nkz'
var fs = require('fs');
const path = require('path');
const HTTPS = require('https');
......@@ -20,6 +20,7 @@ const bodyParser = require('body-parser');
const res = require('express/lib/response');
const { eventNames } = require('process');
const req = require('express/lib/request');
const { compileFunction } = require('vm');
var app = express();
app.use(bodyParser.json());
app.post('/hook', function (req, res) {
......@@ -42,7 +43,7 @@ app.post('/hook', function (req, res) {
{
count++;
opt_1(eventObj.replyToken, eventObj.message.text);
}else if((eventObj.message.text === '1' || eventObj.message.text === '2' || eventObj.message.text === '3' || eventObj.message.text == '4' || eventObj.message.texts == '5') && count ==2)
}else if((eventObj.message.text === '1' || eventObj.message.text === '2' || eventObj.message.text === '3' || eventObj.message.text == '4' || eventObj.message.text == '5') && count ==2)
{
choosen.push(eventObj.message.text);
count++;
......@@ -66,12 +67,26 @@ app.post('/hook', function (req, res) {
{
choosen.push(eventObj.message.text);
count++;
var txt = intersection();
Rmx_comment(eventObj.replyToken);
}else if(count == 7 && end)
{
intersection();
read_file('fin.txt')
Rmx(eventObj.replyToken,n1);
async function read () {
await fs.readFile(dir, 'utf8', (err,data) => {
if(err) {
console.error(err);
return 'err';
}
sleep(500);
real_data =real_data + data + ' ';
console.log(typeof(data));
});
}
console.log('hi');
sleep(1000);
console.log(txt);
Rmx(eventObj.replyToken, txt);
count++;
}else if(count ==8 && end)
{
......@@ -416,41 +431,33 @@ async function err(replyToken)
});
}
async function read_file(dir)
{
await fs.readFile(dir, function(err, data) {
if(err) throw err;
n1 = data.toString().split("\n");
});
}
async function intersection()
{
const spawn = await require('child_process').spawn;
for (var i = 0, j = 0; i < 3; i += 2, j++) {
const result = spawn('python', ['/home/ec2-user/menu_recommand_webpage-1/CHATBOT/fileread_practice.py', directory[i][Number(choosen[i]) - 1], directory[i + 1][Number(choosen[i + 1]) - 1], save_file_name[j]]);
result.stdout.on('data', function (data) {
var result = await spawn('python', ['fileread_practice.py', directory[i][Number(choosen[i]) - 1], directory[i + 1][Number(choosen[i + 1]) - 1], save_file_name[j]]);
await result.stdout.on('data', function (data) {
console.log(data.toString());
});
result.stderr.on('data', function (data) {
await result.stderr.on('data', function (data) {
console.log(data.toString());
});
}
result = spawn('python', ['/home/ec2-user/menu_recommand_webpage-1/CHATBOT/fileread_practice.py', save_file_name[0], save_file_name[1], save_file_name[2]]);
result = await spawn('python', ['fileread_practice.py', save_file_name[0], save_file_name[1], save_file_name[2]]);
result.stdout.on('data', function (data) {
console.log(data.toString());
});
result.stderr.on('data', function (data) {
await result.stderr.on('data', function (data) {
console.log(data.toString());
});
result = spawn('python', ['/home/ec2-user/menu_recommand_webpage-1/CHATBOT/fileread_practice.py', save_file_name[2], directory[4][Number(choosen[4]) - 1], save_file_name[3]]);
result = await spawn('python', ['fileread_practice.py', save_file_name[2], directory[4][Number(choosen[4]) - 1], save_file_name[3]]);
result.stdout.on('data', function (data) {
console.log(data.toString());
});
result.stderr.on('data', function (data) {
await result.stderr.on('data', function (data) {
console.log(data.toString());
});
return 'complete';
}
function sleep(ms) {
......