-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonlyText.js
44 lines (38 loc) · 1.29 KB
/
onlyText.js
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
import ptt_crawler from '@waynechang65/ptt-crawler/lib/ptt_crawler.js';
import { searchOption } from './data.js';
import { FilterOption, TransformToObject } from './function.js';
main();
async function main() {
// *** Initialize ***
await ptt_crawler.initialize();
let content = '';
// split content
let contentArray = [];
for (let item of searchOption) {
const ptt = await ptt_crawler.getResults({
board: item.boardName,
pages: item.pages,
skipPBs: true,
});
// filter data
const filteredData = FilterOption(TransformToObject(ptt), item.option)
// generate log content
content += filteredData.length > 0 ? `<${item.lineTitle}>\n` : ``;
for (let item of filteredData) {
// LINE MESSAGE Length must be between 0 and 5000
if (content.length < 4500) {
content += item.approval + ' 推 - ' + '日期:' + item.date + ' - ' + item.title + ' - ' + item.author + ' - ' + item.url + '\n';
} else {
contentArray.push(content)
content = item.approval + ' 推 - ' + '日期:' + item.date + ' - ' + item.title + ' - ' + item.author + ' - ' + item.url + '\n';
}
}
}
contentArray.push(content)
// *** Close ***
await ptt_crawler.close();
for (let message of contentArray) {
console.log(message)
if(contentArray[contentArray.length - 1] === message) return;
}
}