-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraspberryScraper.js
executable file
·44 lines (39 loc) · 1.36 KB
/
raspberryScraper.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
#!/usr/bin/env node
const rp = require("request-promise");
const chalk = require("chalk");
const figlet = require("figlet");
const $ = require("cheerio");
const url =
"https://marketplace.visualstudio.com/items?itemName=tomWritesCode.raspberryCandy";
const release = new Date("February 19, 2019 11:46:11");
const current = new Date();
function dateDiff() {
const difference = current - release;
return Math.round(difference / (60 * 60 * 24 * 1000));
}
function perDay(string) {
const downloads = string;
return Math.round(parseInt(downloads.slice(0, -9).replace(/,/g, '')) / dateDiff());
}
rp(url)
.then(function (html) {
//success!
console.log(chalk.hex("#00feff").bold("WOW!") + chalk.hex("#e592faff").bold(" raspberryCandy has:"));
console.log(
chalk.hex("#00feff")(
figlet.textSync($("span.installs-text", html).text(), {
font: "Big",
horizontalLayout: "default",
verticalLayout: "default"
})
)
);
console.log(chalk.hex("#00feff").bold("It was released on: " + chalk.hex("#e592faff").bold(release)));
console.log(
chalk.hex("#e592faff").bold("It has been released for: " + chalk.hex("#00feff").bold(dateDiff()) + " days!")
);
console.log(chalk.hex("#00feff").bold("That's about " + chalk.hex("#e592faff").bold(perDay($("span.installs-text", html).text())) + " downloads per day!"));
})
.catch(function (err) {
//handle error
});