-
Notifications
You must be signed in to change notification settings - Fork 37
/
freeones_age.js
32 lines (25 loc) · 1007 Bytes
/
freeones_age.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
async ({ event, args, $axios, $moment, $cheerio, $throw, $log, actorName }) => {
if (event != "actorCreated" && event != "actorCustom")
$throw("Uh oh. You shouldn't use the plugin for this type of event");
$log(`Scraping freeones birth date for ${actorName}, dry mode: ${args.dry || false}...`);
const url = `https://freeones.xxx/${actorName.replace(/ /g, "-")}/profile`;
$log("Getting " + url);
const html = (await $axios.get(url)).data;
const $ = $cheerio.load(html);
const first = $(".profile-meta-item a").toArray()[0];
const href = $(first).attr("href");
const yyyymmdd = href.match(/\d\d\d\d-\d\d-\d\d/);
if (yyyymmdd && yyyymmdd.length) {
const date = yyyymmdd[0];
const timestamp = $moment(date, "YYYY-MM-DD").valueOf();
if (args.dry === true) {
$log("Actor birth date: " + new Date(timestamp).toLocaleDateString());
return {};
}
return {
bornOn: timestamp
};
} else {
$throw("Could not find actor birth date.");
}
};