김연우

modify read_csv.js

Showing 1 changed file with 52 additions and 43 deletions
1 -const csv = require('csv-parser') 1 +var express = require('express');
2 -const fs = require('fs') 2 +const request = require('request');
3 -const results = []; 3 +const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
4 -var choice = "놀거리" 4 +const TOKEN = 'MNiReWsDC5DyJeehZ2gHoqlEVjPsno4ScaswBgXNz0lAVW3v2JizZzhF97DPKxe23jduB+YCcBum+KredegXZnxnrovFVt4fEmgeivWgxOzt/AEJ292DZfPn3uW7xrWfBZrlGXDLaL1AMIBlmwSCcwdB04t89/1O/w1cDnyilFU='
5 - 5 +const fs = require('fs');
6 -//대분류 선택 과정 필요 6 +const path = require('path');
7 -exports.chooseFile = function () { 7 +const HTTPS = require('https');
8 - if (choice == "카페") { 8 +const domain = "2021105581.osschatbot2022.tk"
9 - fs.createReadStream('cafe_list.csv') 9 +const sslport = 23023;
10 - .pipe(csv())
11 - .on('data', (data) => results.push(data))
12 - .on('end', () => {
13 - console.log(results);
14 - });
15 - }
16 - else if (choice == "식사") {
17 - fs.createReadStream('meal_list.csv')
18 - .pipe(csv())
19 - .on('data', (data) => results.push(data))
20 - .on('end', () => {
21 - console.log(results);
22 - });
23 - }
24 - else if (choice == "놀거리") {
25 - fs.createReadStream('play_list.csv')
26 - .pipe(csv())
27 - .on('data', (data) => results.push(data))
28 - .on('end', () => {
29 - console.log(results);
30 - });
31 - }
32 - else if (choice == "술집") {
33 - fs.createReadStream('bar_list.csv')
34 - .pipe(csv())
35 - .on('data', (data) => results.push(data))
36 - .on('end', () => {
37 - console.log(results);
38 - });
39 - }
40 -}
41 -
42 -//chatbot - reply - app.js
43 10
44 var first = false; //첫 시도인지 11 var first = false; //첫 시도인지
45 var second = false; //첫번째 분류 선택했는지 12 var second = false; //첫번째 분류 선택했는지
...@@ -161,6 +128,45 @@ app.post('/hook', function (req, res) { ...@@ -161,6 +128,45 @@ app.post('/hook', function (req, res) {
161 } 128 }
162 } 129 }
163 res.sendStatus(200); 130 res.sendStatus(200);
131 +
132 + chooseFile = function () {
133 + if (destCar == "cafe") {
134 + fs.createReadStream('cafe_list.csv')
135 + .pipe(csv())
136 + .on('data', (data) => results.push(data))
137 + .on('end', () => {
138 + console.log(results);
139 + });
140 + }
141 + else if (destCar == "meal") {
142 + fs.createReadStream('meal_list.csv')
143 + .pipe(csv())
144 + .on('data', (data) => results.push(data))
145 + .on('end', () => {
146 + console.log(results);
147 + });
148 + }
149 + else if (destCar == "play") {
150 + fs.createReadStream('play_list.csv')
151 + .pipe(csv())
152 + .on('data', (data) => results.push(data))
153 + .on('end', () => {
154 + console.log(results);
155 + });
156 + }
157 + else if (destCar == "bar") {
158 + fs.createReadStream('bar_list.csv')
159 + .pipe(csv())
160 + .on('data', (data) => results.push(data))
161 + .on('end', () => {
162 + console.log(results);
163 + });
164 + }
165 + }
166 +
167 + chooseFile();
168 +
169 +
164 }); 170 });
165 171
166 try { 172 try {
...@@ -176,4 +182,7 @@ try { ...@@ -176,4 +182,7 @@ try {
176 } catch (error) { 182 } catch (error) {
177 console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); 183 console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
178 console.log(error); 184 console.log(error);
179 -}
...\ No newline at end of file ...\ No newline at end of file
185 +}
186 +
187 +const csv = require('csv-parser')
188 +const results = [];
......