윤동주

added app.js

Showing 1 changed file with 132 additions and 23 deletions
...@@ -2,21 +2,6 @@ var express = require('express'); ...@@ -2,21 +2,6 @@ var express = require('express');
2 var app = express(); 2 var app = express();
3 const line = require('@line/bot-sdk'); 3 const line = require('@line/bot-sdk');
4 4
5 -
6 -//papago api
7 -var request = require('request');
8 -
9 -//번역 api_url
10 -var translate_api_url = 'https://openapi.naver.com/v1/papago/n2mt';
11 -
12 -//언어감지 api_url
13 -var languagedetect_api_url = 'https://openapi.naver.com/v1/papago/detectLangs'
14 -
15 -// Naver Auth Key
16 -//새로 발급받은 naver papago api id, pw 입력
17 -var client_id = 'xZMx34y7uru1v8lywZ2d';
18 -var client_secret = 'p6L7M7WsH9';
19 -
20 const config = { 5 const config = {
21 channelAccessToken: 'L+RJ15lZgeSoWgeHf9BqgEhm8lYh11qALzPlDV85VGXHfmiKqj3CX1V9DvqakFeJqwWgfQRejsUIWqf/kJuTLQcRC5ws2pyJJbr0VFEXptoYicgiRDzuA51W91dTcFL6/olvLNS1zAf1xO2wxpTGvQdB04t89/1O/w1cDnyilFU=', 6 channelAccessToken: 'L+RJ15lZgeSoWgeHf9BqgEhm8lYh11qALzPlDV85VGXHfmiKqj3CX1V9DvqakFeJqwWgfQRejsUIWqf/kJuTLQcRC5ws2pyJJbr0VFEXptoYicgiRDzuA51W91dTcFL6/olvLNS1zAf1xO2wxpTGvQdB04t89/1O/w1cDnyilFU=',
22 channelSecret: 'e8e139b4cf31d22ed234d62a9b336e74', 7 channelSecret: 'e8e139b4cf31d22ed234d62a9b336e74',
...@@ -43,11 +28,136 @@ app.post('/webhook', line.middleware(config), (req, res) => { ...@@ -43,11 +28,136 @@ app.post('/webhook', line.middleware(config), (req, res) => {
43 28
44 // event handler 29 // event handler
45 function handleEvent(event) { 30 function handleEvent(event) {
46 - if (event.type !== 'message' || event.message.type !== 'text') { 31 + if (event.type !== 'message' || event.message.type !== 'text') {
47 - // ignore non-text-message event 32 + // ignore non-text-message event
48 - return Promise.resolve(null); 33 + return Promise.resolve(null);
49 - } 34 + }
50 - return new Promise(function(resolve, reject) { 35 + return new Promise(function (resolve, reject) {
36 + //내가 짠 것
37 + function getup(shour, smin, ampm) {//몇시에 자려고 할때 언제 일어나면 좋을지
38 + if (shour != '(hour)' && smin != '(minute)') {
39 + ; //탈출
40 + var setTime = new Date();
41 +
42 + if (shour == 12) {
43 + shour = 0;
44 + }
45 +
46 + if (ampm == "AM") {
47 + setTime.setHours(shour);
48 + }
49 + else if (ampm == "PM") {
50 + setTime.setHours(shour + 12);
51 + }
52 +
53 + setTime.setMinutes(smin);
54 +
55 + var res1 = new Date(setTime.getTime() - 270 * 60000);
56 + var res2 = new Date(res1.getTime() - 90 * 60000);
57 + var res3 = new Date(res2.getTime() - 90 * 60000);
58 + var res4 = new Date(res3.getTime() - 90 * 60000);
59 +
60 + function retDate(dateObj) {
61 + var formatted = '';
62 + var pm = false;
63 + if (dateObj.getHours() > 12) {
64 + formatted = dateObj.getHours() - 12;
65 + pm = true;
66 + }
67 + else if (dateObj.getHours() < 12 && dateObj.getHours() != 0) {
68 + formatted = dateObj.getHours();
69 + }
70 + else if (dateObj.getHours() == 0) {
71 + formatted = "12";
72 + }
73 + else if (dateObj.getHours() == 12) {
74 + formatted = "12";
75 + pm = true;
76 + }
77 +
78 + if (dateObj.getMinutes() < 10) {
79 + formatted = formatted + ":0" + dateObj.getMinutes();
80 + }
81 + else {
82 + formatted = formatted + ":" + dateObj.getMinutes();
83 + }
84 +
85 + if (pm == true) {
86 + formatted = formatted + " PM";
87 + }
88 + else {
89 + formatted = formatted + " AM";
90 + }
91 + return formatted;
92 + }
93 +
94 + console.log(String(retDate(res1)));
95 + console.log(String(retDate(res2)));
96 + console.log(String(retDate(res3)));
97 + console.log(String(retDate(res4)));
98 +
99 + $('#results').fadeIn();
100 + $('#feedback').fadeIn();
101 + $('#ad').fadeIn();
102 + } // end hour/minute check if
103 + else {
104 + alert("Please select an hour and a minute before trying to calculate!");
105 + } // end not-filled check
106 + };// end calculate
107 +})};
108 +
109 +
110 +function sleep(ghour, gmin, ampm) {
111 + //$('#start').hide();
112 + var zDate = new Date();
113 +
114 + var res1 = new Date(zDate.getTime() + 104*60000);
115 + var res2 = new Date(res1.getTime() + 90*60000);
116 + var res3 = new Date(res2.getTime() + 90*60000);
117 + var res4 = new Date(res3.getTime() + 90*60000);
118 + var res5 = new Date(res4.getTime() + 90*60000);
119 + var res6 = new Date(res5.getTime() + 90*60000);
120 +
121 + function retDate(dateObj) {
122 + var formatted = '';
123 + var pm = false;
124 + if(dateObj.getHours() > 12) {
125 + formatted = dateObj.getHours() - 12;
126 + pm = true;
127 + } else if(dateObj.getHours() < 12 && dateObj.getHours() != 0) {
128 + formatted = dateObj.getHours();
129 + } else if(dateObj.getHours() == 0) {
130 + formatted = "12";
131 + } else if(dateObj.getHours() == 12) {
132 + formatted = "12";
133 + pm = true;
134 + }
135 + if(dateObj.getMinutes() < 10) {
136 + formatted = formatted + ":0" + dateObj.getMinutes();
137 + } else {
138 + formatted = formatted + ":" + dateObj.getMinutes();
139 + }
140 + if(pm == true) {
141 + formatted = formatted + " PM";
142 + } else {
143 + formatted = formatted + " AM";
144 + }
145 + return formatted;
146 + }
147 +
148 + console.log(String(retDate(res1)));
149 + console.log(String(retDate(res2)));
150 + console.log(String(retDate(res3)));
151 + console.log(String(retDate(res4)));
152 + console.log(String(retDate(res5)));
153 + console.log(String(retDate(res6)));
154 +
155 + $('#resultsNow').fadeIn();
156 + $('#feedback').fadeIn();
157 + $('#ad').fadeIn();
158 +});
159 +});
160 +/*
51 //언어 감지 option 161 //언어 감지 option
52 var detect_options = { 162 var detect_options = {
53 url : languagedetect_api_url, 163 url : languagedetect_api_url,
...@@ -104,9 +214,8 @@ function handleEvent(event) { ...@@ -104,9 +214,8 @@ function handleEvent(event) {
104 } 214 }
105 215
106 }); 216 });
107 - 217 +*/
108 - }); 218 +
109 - }
110 219
111 app.listen(3000, function () { 220 app.listen(3000, function () {
112 console.log('Linebot listening on port 3000!'); 221 console.log('Linebot listening on port 3000!');
......