Skip to content

Commit 5725137

Browse files
committed
Init
1 parent 09eff87 commit 5725137

File tree

8 files changed

+593
-0
lines changed

8 files changed

+593
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,5 @@ dist
102102

103103
# TernJS port file
104104
.tern-port
105+
106+
.DS_Store

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
# playboard-crawler
22
Playboard YouTube Super Chat Statistics Crawler
3+
4+
> Still WIP
5+
6+
---
7+
Usage:
8+
```bash
9+
$ yarn # Install dependencies
10+
$ yarn start # Start the crawler
11+
```
12+
---
13+
![](assets/img/demo.png)
14+

assets/.DS_Store

6 KB
Binary file not shown.

assets/img/demo.png

80.7 KB
Loading

index.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const cheerio = require('cheerio');
2+
const fetch = require('node-fetch');
3+
const currency = require('currency.js');
4+
5+
const USD = value => currency(value);
6+
const USD_REGEX = /^\$/;
7+
8+
const NTD = value => currency(value, { symbol: 'NT$', precision: 0 });
9+
const NTD_REGEX = /^NT\$/;
10+
11+
getSum = async (getCount) => {
12+
if (!(getCount)) {
13+
throw new Error("Argument missing");
14+
}
15+
fetch('https://playboard.co/en/youtube-ranking/most-superchatted-v-tuber-channels-in-worldwide-daily')
16+
.then(function (response) {
17+
return response.text();
18+
})
19+
.then(function (body) {
20+
let $ = cheerio.load(body);
21+
let title = $('title').text();
22+
console.log(title);
23+
console.log();
24+
25+
let name = [];
26+
let data = [];
27+
$('.name__label h3').each(function () {
28+
name.push($(this).text());
29+
});
30+
$('.fluc-label.fluc-label--en.fluc-label--symbol-math.up').each(function () {
31+
data.push($(this).text());
32+
});
33+
34+
let sum = 0;
35+
let n = data.length;
36+
let counter = 1;
37+
let currencyType;
38+
39+
if (NTD_REGEX.test(data[0])) {
40+
currencyType = "NTD";
41+
} else if (USD_REGEX.test(data[0])) {
42+
currencyType = "USD";
43+
}
44+
45+
for (let i = 0; i < n && counter <= getCount; i += 2, counter++) {
46+
console.log(counter);
47+
console.log(name[counter - 1]);
48+
console.log(data[i]);
49+
// console.log(currency(data[i]).value);
50+
sum += currency(data[i]).value;
51+
console.log();
52+
}
53+
counter--;
54+
console.log(`Data Count: ${counter}`);
55+
console.log(`Date in local time: ${Date().toLocaleString()}`);
56+
switch (currencyType) {
57+
case "NTD":
58+
console.log(`Sum: ${NTD(sum).format()}`);
59+
break;
60+
case "USD":
61+
console.log(`sum: ${USD(sum).format()}`);
62+
break;
63+
}
64+
});
65+
}
66+
67+
getSum(10);

package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "playboard-crawler",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"start": "node index.js"
6+
},
7+
"main": "index.js",
8+
"repository": "https://github.com/edisonlee55/playboard-crawler.git",
9+
"author": "Edison Lee <[email protected]>",
10+
"license": "MIT",
11+
"dependencies": {
12+
"cheerio": "^1.0.0-rc.5",
13+
"currency.js": "^2.0.3",
14+
"node-fetch": "^2.6.1",
15+
"puppeteer": "^7.1.0",
16+
"scroll-to-bottomjs": "^1.1.0"
17+
}
18+
}

0 commit comments

Comments
 (0)