김연우

add random sorting process

Showing 1 changed file with 75 additions and 64 deletions
1 -var express = require('express');
2 -const request = require('request');
3 -const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
4 -const TOKEN = 'MNiReWsDC5DyJeehZ2gHoqlEVjPsno4ScaswBgXNz0lAVW3v2JizZzhF97DPKxe23jduB+YCcBum+KredegXZnxnrovFVt4fEmgeivWgxOzt/AEJ292DZfPn3uW7xrWfBZrlGXDLaL1AMIBlmwSCcwdB04t89/1O/w1cDnyilFU='
5 -const fs = require('fs');
6 -const path = require('path');
7 -const HTTPS = require('https');
8 -const domain = "2021105581.osschatbot2022.tk"
9 -const sslport = 23023;
10 1
11 var first = false; //첫 시도인지 2 var first = false; //첫 시도인지
12 var second = false; //첫번째 분류 선택했는지 3 var second = false; //첫번째 분류 선택했는지
13 var destCar = ""; 4 var destCar = "";
5 +var destination = [];
14 6
15 const bodyParser = require('body-parser'); 7 const bodyParser = require('body-parser');
16 var app = express(); 8 var app = express();
...@@ -57,81 +49,80 @@ app.post('/hook', function (req, res) { ...@@ -57,81 +49,80 @@ app.post('/hook', function (req, res) {
57 { 49 {
58 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: { 50 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
59 "replyToken": eventObj.replyToken, 51 "replyToken": eventObj.replyToken,
60 - "messages": [{ "type": "text", "text": "[식사] 키워드를 선택해주세요\n1. 양식\n2. 한식\n3. 중식\n4. 일식\n5. 기타 " }] 52 + "messages": [{ "type": "text", "text": "[식사] 키워드를 선택해주세요\n1. 양식\n2. 한식\n3. 중식\n4. 일식\n5. 기타\n(숫자만 입력해주세요)" }]
61 } 53 }
62 }, (error, response, body) => { 54 }, (error, response, body) => {
63 console.log(body) 55 console.log(body)
64 }); 56 });
65 - destCar = "meal"; 57 + destCar = "meal";
66 - } else if (eventObj.message.text == 2) { //카페 선택 58 + } else if (eventObj.message.text == 2) { //카페 선택
67 request.post( 59 request.post(
68 { 60 {
69 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: { 61 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
70 "replyToken": eventObj.replyToken, 62 "replyToken": eventObj.replyToken,
71 - "messages": [{ "type": "text", "text": "[카페] 키워드를 선택해주세요\n1. 감성\n2. 카공\n3. 디저트" }] 63 + "messages": [{ "type": "text", "text": "[카페] 키워드를 선택해주세요\n1. 감성\n2. 카공\n3. 디저트\n(숫자만 입력해주세요)" }]
72 } 64 }
73 }, (error, response, body) => { 65 }, (error, response, body) => {
74 console.log(body) 66 console.log(body)
75 }); 67 });
76 - destCar = "cafe"; 68 + destCar = "cafe";
77 } else if (eventObj.message.text == 3) { //술 선택 69 } else if (eventObj.message.text == 3) { //술 선택
78 request.post( 70 request.post(
79 { 71 {
80 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: { 72 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
81 "replyToken": eventObj.replyToken, 73 "replyToken": eventObj.replyToken,
82 - "messages": [{ "type": "text", "text": "[술] 키워드를 선택해주세요\n1. 소주\n2. 이자카야\n3. 막걸리\n4. 맥주" }] 74 + "messages": [{ "type": "text", "text": "[술] 키워드를 선택해주세요\n1. 소주\n2. 이자카야\n3. 막걸리\n4. 맥주\n(숫자만 입력해주세요)" }]
83 } 75 }
84 }, (error, response, body) => { 76 }, (error, response, body) => {
85 console.log(body) 77 console.log(body)
86 }); 78 });
87 - destCar = "bar" 79 + destCar = "bar"
88 } else if (eventObj.message.text == 4) { //놀거리 선택 80 } else if (eventObj.message.text == 4) { //놀거리 선택
89 request.post( 81 request.post(
90 { 82 {
91 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: { 83 url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
92 "replyToken": eventObj.replyToken, 84 "replyToken": eventObj.replyToken,
93 - "messages": [{ "type": "text", "text": "[놀거리] 키워드를 선택해주세요\n1. 노래방\n2. 피시방\n3. 기타" }] 85 + "messages": [{ "type": "text", "text": "[놀거리] 키워드를 선택해주세요\n1. 노래방\n2. 피시방\n3. 기타\n(숫자만 입력해주세요)" }]
94 } 86 }
95 }, (error, response, body) => { 87 }, (error, response, body) => {
96 console.log(body) 88 console.log(body)
97 }); 89 });
98 - destCar = "play" 90 + destCar = "play"
99 } 91 }
100 - 92 + chooseFile();
101 second = true; 93 second = true;
102 - 94 +
103 } 95 }
104 96
105 else if (first == true && second == true) { 97 else if (first == true && second == true) {
106 if (destCar == "meal") { 98 if (destCar == "meal") {
107 - if (eventObj.message.text == 1) { destination = "western"; console.log(destination) } 99 + if (eventObj.message.text == 1) { var randpick = randomNum(0, 6); destination = results[randpick] }
108 - else if (eventObj.message.text == 2) { destination = "korean"; console.log(destination)} 100 + else if (eventObj.message.text == 2) { var randpick = randomNum(7, 19); destination = results[randpick] }
109 - else if (eventObj.message.text == 3) { destination = "chinese"; console.log(destination)} 101 + else if (eventObj.message.text == 3) { var randpick = randomNum(20, 25); destination = results[randpick] }
110 - else if (eventObj.message.text == 4) { destination = "japanese"; console.log(destination)} 102 + else if (eventObj.message.text == 4) { var randpick = randomNum(26, 36); destination = results[randpick] }
111 - else if (eventObj.message.text == 5) { destination = "meal_etc"; console.log(destination) } 103 + else if (eventObj.message.text == 5) { var randpick = randomNum(37, 46); destination = results[randpick] }
112 } 104 }
113 else if (destCar == "cafe") { 105 else if (destCar == "cafe") {
114 - if (eventObj.message.text == 1) { destination = "sns"; console.log(destination) } 106 + if (eventObj.message.text == 1) { var randpick = randomNum(0, 5); destination = results[randpick] }
115 - else if (eventObj.message.text == 2) { destination = "study"; console.log(destination)} 107 + else if (eventObj.message.text == 2) { var randpick = randomNum(6, 12); destination = results[randpick] }
116 - else if (eventObj.message.text == 3) { destination = "dessert"; console.log(destination)} 108 + else if (eventObj.message.text == 3) { var randpick = randomNum(13, 17); destination = results[randpick] }
117 } 109 }
118 else if (destCar == "bar") { 110 else if (destCar == "bar") {
119 - if (eventObj.message.text == 1) { destination = "soju"; console.log(destination) } 111 + if (eventObj.message.text == 1) { var randpick = randomNum(0, 5); destination = results[randpick] }
120 - else if (eventObj.message.text == 2) { destination = "izakaya"; console.log(destination)} 112 + else if (eventObj.message.text == 2) { var randpick = randomNum(6, 11); destination = results[randpick] }
121 - else if (eventObj.message.text == 3) { destination = "makgeolli"; console.log(destination)} 113 + else if (eventObj.message.text == 3) { var randpick = randomNum(12, 15); destination = results[randpick] }
122 - else if (eventObj.message.text == 4) { destination = "beer"; console.log(destination)} 114 + else if (eventObj.message.text == 4) { var randpick = randomNum(16, 20); destination = results[randpick] }
123 } 115 }
124 else if (destCar == "play") { 116 else if (destCar == "play") {
125 - if (eventObj.message.text == 1) { destination = "karaoke"; console.log(destination) } 117 + if (eventObj.message.text == 1) { var randpick = randomNum(0, 3); destination = results[randpick] }
126 - else if (eventObj.message.text == 2) { destination = "izakaya"; console.log(destination)} 118 + else if (eventObj.message.text == 2) { var randpick = randomNum(4, 8); destination = results[randpick] }
127 - else if (eventObj.message.text == 3) { destination = "play_etc"; console.log(destination)} 119 + else if (eventObj.message.text == 3) { var randpick = randomNum(9, 13); destination = results[randpick] }
128 } 120 }
121 +
122 +
129 } 123 }
130 res.sendStatus(200); 124 res.sendStatus(200);
131 125
132 -
133 - chooseFile();
134 -
135 126
136 }); 127 });
137 128
...@@ -151,39 +142,59 @@ try { ...@@ -151,39 +142,59 @@ try {
151 } 142 }
152 143
153 const csv = require('csv-parser') 144 const csv = require('csv-parser')
154 -const results = []; 145 +const results = [];
155 146
156 chooseFile = function () { 147 chooseFile = function () {
157 if (destCar == "cafe") { 148 if (destCar == "cafe") {
158 - fs.createReadStream('cafe_list.csv') 149 + fs.createReadStream('cafe_list.csv')
159 - .pipe(csv()) 150 + .pipe(csv())
160 - .on('data', (data) => results.push(data)) 151 + .on('data', (data) => results.push(data))
161 - .on('end', () => { 152 + .on('end', () => {
162 - console.log(results); 153 + console.log(results);
163 - }); 154 + });
164 } 155 }
165 else if (destCar == "meal") { 156 else if (destCar == "meal") {
166 - fs.createReadStream('meal_list.csv') 157 + fs.createReadStream('meal_list.csv')
167 - .pipe(csv()) 158 + .pipe(csv())
168 - .on('data', (data) => results.push(data)) 159 + .on('data', (data) => results.push(data))
169 - .on('end', () => { 160 + .on('end', () => {
170 - console.log(results); 161 + console.log(results);
171 - }); 162 + });
172 } 163 }
173 else if (destCar == "play") { 164 else if (destCar == "play") {
174 - fs.createReadStream('play_list.csv') 165 + fs.createReadStream('play_list.csv')
175 - .pipe(csv()) 166 + .pipe(csv())
176 - .on('data', (data) => results.push(data)) 167 + .on('data', (data) => results.push(data))
177 - .on('end', () => { 168 + .on('end', () => {
178 - console.log(results); 169 + console.log(results);
179 - }); 170 + });
180 } 171 }
181 else if (destCar == "bar") { 172 else if (destCar == "bar") {
182 - fs.createReadStream('bar_list.csv') 173 + fs.createReadStream('bar_list.csv')
183 - .pipe(csv()) 174 + .pipe(csv())
184 - .on('data', (data) => results.push(data)) 175 + .on('data', (data) => results.push(data))
185 - .on('end', () => { 176 + .on('end', () => {
186 - console.log(results); 177 + console.log(results);
187 - }); 178 + });
188 } 179 }
189 - }
...\ No newline at end of file ...\ No newline at end of file
180 +}
181 +
182 +function randomNum(min, max) {
183 + var randNum = Math.floor(Math.random() * (max - min + 1)) + min;
184 + return randNum;
185 +}
186 +
187 +function getX() {
188 + return destination.x;
189 +}
190 +function getY() {
191 + return destination.y;
192 +}
193 +function getName() {
194 + return destination.name;
195 +}
196 +function getAddress() {
197 + return destination.address;
198 +}
199 +
200 +export { getX, getY, getName, getAddress }
...\ No newline at end of file ...\ No newline at end of file
......