Ubuntu

0613 우산여부확인

......@@ -2,11 +2,17 @@ var express = require('express');//express 모듈을 사용
var qs = require('querystring')
const request = require('request');//request 모듈을 사용
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'//라인 api
var NOW = new Date()
var YEAR = NOW.getFullYear()
var MONTH= NOW.getMonth()+1
var DATE= NOW.getDate();
var NOWDATE= YEAR.toString() + MONTH.toString() + DATE.toString()
const WEATHER_URL=`http://apis.data.go.kr/1360000/VilageFcstInfoService/getVilageFcst?serviceKey=StHx15%2FPZFKIJvR5AtCu8uyowAtnEYHpAXR%2B5XYYN6OWDt%2BCz15z%2Fxn%2FDiV%2FLN9%2BY5YSPZUPUnCq982CiBupmw%3D%3D&numOfRows=10&pageNo=1&base_date=${NOWDATE}&base_time=0230&nx=55&ny=127&dataType=JSON`
const TOKEN = 'RbPAXRYWub0evg2yyi7oiHytZsZsE0JtbZgRYZNZDU1vjpJkOwGqwh+aKTYKVhVHh6LZOUVZLl84NQQlNWNbXR9hUhPEiLEK0cie4O3OlKUuEe/3wAsjPu7HbRi1zn9BsR3Qr4pcqmiIKP8HRUKvEwdB04t89/1O/w1cDnyilFU='
const MAP_URL = 'https://naveropenapi.apigw.ntruss.com/map-static/v2/raster?w=300&h=300&center=127.1054221,37.3591614&level=16&format=jpg'
const GEO_URL = 'https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode'
const MAP_ID = '8p40s890zx'
const MAP_SECRET = 'twTXrNPSuUYNU4MG7bV9KjXzpTADVDQAlMFK7kAZ'
const fs = require('fs');
const path = require('path');
const HTTPS = require('https');
......@@ -14,7 +20,6 @@ const domain = "www.osschat.tk"
const sslport = 23023;
const bodyParser = require('body-parser');
var app = express();
var target = 'en'
var premessage='premessage'
var start ='start'
......@@ -22,6 +27,8 @@ var start ='start'
app.use(bodyParser.json());
app.use(express.static('statics'));
app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
......@@ -34,8 +41,7 @@ app.post('/hook', function (req, res) {
console.log('[request source] ', eventObj.source);
console.log('[request message]', eventObj.message);
trans(eventObj.replyToken, eventObj.message.text);
geo(eventObj.replyToken, eventObj.message.text);
rain(eventObj.replyToken, eventObj.message.text);
res.sendStatus(200);
......@@ -43,32 +49,47 @@ app.post('/hook', function (req, res) {
function geo (replyToekn, message){
if(premessage != '길찾기')
function rain (replyToken, message){
if(message != '오늘 옷')
{
return
}
start=qs.escape(message)
const GEO_URL = `https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode?query=${start}`
request.get(
{
url: GEO_URL,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-NCP-APIGW-API-KEY-ID': `${MAP_ID}`,
'X-NCP-APIGW-API-KEY': `${MAP_SECRET}`
request.get(
{
url: WEATHER_URL,
json:true
},(error, response, body) => {
if(!error && response.statusCode == 200) {
console.log(body.message);
if(body.POP>=50){
var rainMessage = "꼭! 우산을 챙기세요";
}else{
var rainMessage= "우산이 굳이 필요하지는 않습니다."
}
},function(error, response, body) {
console.log(body)
});
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken":replyToken,
"messages":[
{
"type":"text",
"text":rainMessage
}
]
}
},(error, response, body) => {
console.log(body)
});
}
});
}
/*
function trans(replyToken, message) {
......@@ -109,6 +130,7 @@ function trans(replyToken, message) {
});
}
*/
try {
const option = {
......