Runs every 1 hrs
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 { email as email2 } from "https://esm.town/v/std/email?v=9";
import { set } from "https://esm.town/v/std/set?v=11";
import { njuskaloSniff } from "https://esm.town/v/kajgod/njuskaloSniff?v=1";
import { njuskaloData } from "https://esm.town/v/tvalincic/njuskaloData";
export const njuskaloCrawl = async () => {
const dryRun = true;
let email = "Njuškalo news for you: \r\n";
let subject = "Njuškalo: ";
const data = njuskaloData;
if (data?.keywords?.length < 1)
return -1; // no keywords set
let newValues = false;
for (let i = 0; i < data.keywords.length; i++) {
const v = data.keywords[i];
const rsp = await njuskaloSniff(v.split(" "));
const { title = "", price = 0, url = "" } = rsp;
if (title === "" || price === 0 || url === "")
continue;
if (data.registeredTitles.includes(url))
continue;
data.registeredTitles[i] = url;
data.sentData[i] = rsp;
email += `
Title: ${title}
Keywords: ${v}
Price: ${price} eur
URL: https://www.njuskalo.hr${url}
`;
if (subject.length < 100) {
subject += title;
}
else {
subject += "...itd...";
}
newValues = true;
}
await set("njuskaloData", njuskaloData);
if (newValues) {
await email2({ text: email, subject });
return 1;
}
return 0;
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023