김연우

add random sorting process

Showing 1 changed file with 75 additions and 64 deletions
var express = require('express');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const TOKEN = 'MNiReWsDC5DyJeehZ2gHoqlEVjPsno4ScaswBgXNz0lAVW3v2JizZzhF97DPKxe23jduB+YCcBum+KredegXZnxnrovFVt4fEmgeivWgxOzt/AEJ292DZfPn3uW7xrWfBZrlGXDLaL1AMIBlmwSCcwdB04t89/1O/w1cDnyilFU='
const fs = require('fs');
const path = require('path');
const HTTPS = require('https');
const domain = "2021105581.osschatbot2022.tk"
const sslport = 23023;
var first = false; //첫 시도인지
var second = false; //첫번째 분류 선택했는지
var destCar = "";
var destination = [];
const bodyParser = require('body-parser');
var app = express();
......@@ -57,81 +49,80 @@ app.post('/hook', function (req, res) {
{
url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
"replyToken": eventObj.replyToken,
"messages": [{ "type": "text", "text": "[식사] 키워드를 선택해주세요\n1. 양식\n2. 한식\n3. 중식\n4. 일식\n5. 기타 " }]
"messages": [{ "type": "text", "text": "[식사] 키워드를 선택해주세요\n1. 양식\n2. 한식\n3. 중식\n4. 일식\n5. 기타\n(숫자만 입력해주세요)" }]
}
}, (error, response, body) => {
console.log(body)
});
destCar = "meal";
} else if (eventObj.message.text == 2) { //카페 선택
destCar = "meal";
} else if (eventObj.message.text == 2) { //카페 선택
request.post(
{
url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
"replyToken": eventObj.replyToken,
"messages": [{ "type": "text", "text": "[카페] 키워드를 선택해주세요\n1. 감성\n2. 카공\n3. 디저트" }]
"messages": [{ "type": "text", "text": "[카페] 키워드를 선택해주세요\n1. 감성\n2. 카공\n3. 디저트\n(숫자만 입력해주세요)" }]
}
}, (error, response, body) => {
console.log(body)
});
destCar = "cafe";
destCar = "cafe";
} else if (eventObj.message.text == 3) { //술 선택
request.post(
{
url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
"replyToken": eventObj.replyToken,
"messages": [{ "type": "text", "text": "[술] 키워드를 선택해주세요\n1. 소주\n2. 이자카야\n3. 막걸리\n4. 맥주" }]
"messages": [{ "type": "text", "text": "[술] 키워드를 선택해주세요\n1. 소주\n2. 이자카야\n3. 막걸리\n4. 맥주\n(숫자만 입력해주세요)" }]
}
}, (error, response, body) => {
console.log(body)
});
destCar = "bar"
destCar = "bar"
} else if (eventObj.message.text == 4) { //놀거리 선택
request.post(
{
url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
"replyToken": eventObj.replyToken,
"messages": [{ "type": "text", "text": "[놀거리] 키워드를 선택해주세요\n1. 노래방\n2. 피시방\n3. 기타" }]
"messages": [{ "type": "text", "text": "[놀거리] 키워드를 선택해주세요\n1. 노래방\n2. 피시방\n3. 기타\n(숫자만 입력해주세요)" }]
}
}, (error, response, body) => {
console.log(body)
});
destCar = "play"
destCar = "play"
}
chooseFile();
second = true;
}
else if (first == true && second == true) {
if (destCar == "meal") {
if (eventObj.message.text == 1) { destination = "western"; console.log(destination) }
else if (eventObj.message.text == 2) { destination = "korean"; console.log(destination)}
else if (eventObj.message.text == 3) { destination = "chinese"; console.log(destination)}
else if (eventObj.message.text == 4) { destination = "japanese"; console.log(destination)}
else if (eventObj.message.text == 5) { destination = "meal_etc"; console.log(destination) }
if (eventObj.message.text == 1) { var randpick = randomNum(0, 6); destination = results[randpick] }
else if (eventObj.message.text == 2) { var randpick = randomNum(7, 19); destination = results[randpick] }
else if (eventObj.message.text == 3) { var randpick = randomNum(20, 25); destination = results[randpick] }
else if (eventObj.message.text == 4) { var randpick = randomNum(26, 36); destination = results[randpick] }
else if (eventObj.message.text == 5) { var randpick = randomNum(37, 46); destination = results[randpick] }
}
else if (destCar == "cafe") {
if (eventObj.message.text == 1) { destination = "sns"; console.log(destination) }
else if (eventObj.message.text == 2) { destination = "study"; console.log(destination)}
else if (eventObj.message.text == 3) { destination = "dessert"; console.log(destination)}
if (eventObj.message.text == 1) { var randpick = randomNum(0, 5); destination = results[randpick] }
else if (eventObj.message.text == 2) { var randpick = randomNum(6, 12); destination = results[randpick] }
else if (eventObj.message.text == 3) { var randpick = randomNum(13, 17); destination = results[randpick] }
}
else if (destCar == "bar") {
if (eventObj.message.text == 1) { destination = "soju"; console.log(destination) }
else if (eventObj.message.text == 2) { destination = "izakaya"; console.log(destination)}
else if (eventObj.message.text == 3) { destination = "makgeolli"; console.log(destination)}
else if (eventObj.message.text == 4) { destination = "beer"; console.log(destination)}
if (eventObj.message.text == 1) { var randpick = randomNum(0, 5); destination = results[randpick] }
else if (eventObj.message.text == 2) { var randpick = randomNum(6, 11); destination = results[randpick] }
else if (eventObj.message.text == 3) { var randpick = randomNum(12, 15); destination = results[randpick] }
else if (eventObj.message.text == 4) { var randpick = randomNum(16, 20); destination = results[randpick] }
}
else if (destCar == "play") {
if (eventObj.message.text == 1) { destination = "karaoke"; console.log(destination) }
else if (eventObj.message.text == 2) { destination = "izakaya"; console.log(destination)}
else if (eventObj.message.text == 3) { destination = "play_etc"; console.log(destination)}
if (eventObj.message.text == 1) { var randpick = randomNum(0, 3); destination = results[randpick] }
else if (eventObj.message.text == 2) { var randpick = randomNum(4, 8); destination = results[randpick] }
else if (eventObj.message.text == 3) { var randpick = randomNum(9, 13); destination = results[randpick] }
}
}
res.sendStatus(200);
chooseFile();
});
......@@ -151,39 +142,59 @@ try {
}
const csv = require('csv-parser')
const results = [];
const results = [];
chooseFile = function () {
if (destCar == "cafe") {
fs.createReadStream('cafe_list.csv')
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', () => {
console.log(results);
});
fs.createReadStream('cafe_list.csv')
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', () => {
console.log(results);
});
}
else if (destCar == "meal") {
fs.createReadStream('meal_list.csv')
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', () => {
console.log(results);
});
fs.createReadStream('meal_list.csv')
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', () => {
console.log(results);
});
}
else if (destCar == "play") {
fs.createReadStream('play_list.csv')
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', () => {
console.log(results);
});
fs.createReadStream('play_list.csv')
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', () => {
console.log(results);
});
}
else if (destCar == "bar") {
fs.createReadStream('bar_list.csv')
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', () => {
console.log(results);
});
fs.createReadStream('bar_list.csv')
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', () => {
console.log(results);
});
}
}
\ No newline at end of file
}
function randomNum(min, max) {
var randNum = Math.floor(Math.random() * (max - min + 1)) + min;
return randNum;
}
function getX() {
return destination.x;
}
function getY() {
return destination.y;
}
function getName() {
return destination.name;
}
function getAddress() {
return destination.address;
}
export { getX, getY, getName, getAddress }
\ No newline at end of file
......