장수창

added yongin crawling

......@@ -2,11 +2,12 @@ var express = require('express');
const request = require('request');
const axios = require("axios");
const cheerio = require("cheerio");
const url = "http://ncov.mohw.go.kr/"; // 질병관리본부 url
const ncov_url = "http://ncov.mohw.go.kr/"; // 질병관리본부 url
const yongin_url = 'http://www.yongin.go.kr/health/ictsd/INC_selectIctsdPatntList.do?q_currPage=1&q_rowPerPage=10&_=1592578382959'; // 용인시
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
const TOKEN = ''
const TOKEN = '///////'
const NAVER_NEWS_ID = ''
const NAVER_NEWS_SECRET = ''
const fs = require('fs');
......@@ -14,10 +15,10 @@ const path = require('path');
const HTTPS = require('https');
const domain = "www.osschatbot2020.tk"
const sslport = 23023;
const bodyParser = require('body-parser');
var app = express();
// broadcast route
var period_broadcast = 50000;
var count_broadcast = 0;
......@@ -57,10 +58,10 @@ app.post('/hook', function (req, res) {
res.sendStatus(200);
});
//reply
// reply
function replyNationWide(eventObj) {
//read status
request.post(url, function (err, res, body) {
request.post(ncov_url, function (err, res, body) {
const $ = cheerio.load(body)
let parentTag = $("div.liveNum ul.liveNum li");
......@@ -115,7 +116,7 @@ function replyNationWide(eventObj) {
}
//hello
// hello
function hello(eventObj) {
request.post(
......@@ -140,6 +141,10 @@ function hello(eventObj) {
"text":"코로나 19 관련 뉴스는 '뉴스'를 타이핑 해주세요."
},
{
"type":"text",
"text":"감사합니다."
},
{
"type": "sticker",
"packageId": "11539",
"stickerId": "52114110"
......@@ -152,9 +157,24 @@ function hello(eventObj) {
});
}
// Broadcast
// Broadcast yongin
function broadcast(){
request.post(yongin_url, function (err, res, body) {
const $ = cheerio.load(body)
let parentTag = $("div.view_content");
let resultArr = [];
parentTag.each(function (i, elem) {
let itemObj = {
text: $(this).find("p").text(),
}
resultArr.push(itemObj);
})
var fs = require('fs');
var array = fs.readFileSync('yongin.txt').toString().split("\n");
request.post(
{
url: BROAD_TARGET_URL,
......@@ -165,42 +185,21 @@ function broadcast(){
"messages":[
{
"type":"text",
"text":"Hello, user"
"text":"용인시 확진자의 동선이 공개되었습니다."
},
{
"type":"text",
"text":"May I help you?"
"type": "sticker",
"packageId": "11539",
"stickerId": "52114110"
}
]
}
},(error, response, body) => {
console.log(body)
});
}
// Multicast User
// request.post(
// {
// url: MULTI_TARGET_URL,
// headers: {
// 'Authorization': `Bearer ${TOKEN}`
// },
// json: {
// "to": [`${USER_ID}`],
// "messages":[
// {
// "type":"text",
// "text":"용인시"
// },
// {
// "type":"text",
// "text":"용인시"
// }
// ]
// }
// },(error, response, body) => {
// console.log(body)
// });
})
}
//reply news
function replyNews(eventObj) {
......