-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
167 lines (159 loc) · 6.54 KB
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import fetch from 'node-fetch';
import jsdom from 'jsdom';
const { JSDOM } = jsdom;
import * as fs from 'fs'
//====================================================================================
// 初期設定
const url = '<スクレイピング先URLを入力>';
const bot_name = '<BOT名称入力>';
const txt_path = '<出力ファイル指定>';
const token = '<Tokenを入力>';
const btn_name = '<スクレイピング先サイトボタン名称>';
//====================================================================================
//------------------------------------------------------------------------------------
//保守用
const ver = "1.0 β";
const admin = "<運営保守担当者入力>";
//------------------------------------------------------------------------------------
(async () => {
const res = await fetch(url);
const html = await res.text();
const dom = new JSDOM(html);
const document = dom.window.document;
const data = document.querySelector('#frame-97 > div.panel-body.block > article > div:nth-child(1)');
const msg = data.textContent;
if( fs.existsSync(txt_path) ){ // txtファイル存在確認
let read = fs.readFileSync(txt_path); // txt読み込み
if(read == msg){ // データ判定
console.log("Don't need to renew;");
}else{ // データに変更があった場合
fs.writeFile(txt_path, msg ,function(err, result) { // 変更を保存
if(err) console.log('error', err);
});
fetch('https://api.line.me/v2/bot/message/broadcast', { // LINEへcurlでpush
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer {${token}}`
},
body: JSON.stringify(
{
"messages":[
{
"type": "flex",
"altText": "お知らせ",
"contents":
{
"type": "bubble",
"header": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "新着お知らせ",
"color": "#ffffff",
"align": "center",
"weight": "bold",
"size": "xl"
}
],
"background": {
"type": "linearGradient",
"angle": "62deg",
"startColor": "#F091C7",
"endColor": "#F7CE68"
}
},
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": msg,
"wrap": true,
"margin": "none",
"size": "sm"
}
],
"backgroundColor": "#f6dfeb",
"offsetTop": "none",
"offsetBottom": "none",
"offsetStart": "none",
"offsetEnd": "none",
"cornerRadius": "md",
"paddingAll": "sm"
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "▶ 詳細は下記のボタンより公式HPをご確認ください。",
"wrap": true,
"size": "sm"
},
{
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "button",
"action": {
"type": "uri",
"label": btn_name,
"uri": url
},
"color": "#ffffff"
}
],
"backgroundColor": "#addfff",
"cornerRadius": "xxl",
"margin": "sm"
}
],
"margin": "xxl"
}
]
},
"footer": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "separator"
},
{
"type": "text",
"margin": "sm",
"size": "xs",
"text": bot_name + ver,
"align": "end"
},
{
"type": "text",
"text": "運営・管理:" + admin,
"size": "xxs",
"align": "end",
"margin": "xs"
}
]
}
}
}
]
}
)});
}
}else{ // txt存在しない場合
fs.writeFile(txt_path, msg ,function(err, result) { // 変更を保存
if(err) console.log('error', err);
});
}
})();