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
import { fetch } from "https://esm.town/v/std/fetch";
import { set } from "https://esm.town/v/std/set?v=11";
import { topHNThreadByHour } from "https://esm.town/v/elsif_maj/topHNThreadByHour";
export let nameTopHNThreadCron = (async () => {
// Cheerio parses markup and provides an API to interact with the resulting data structure
const cheerio = await import("npm:cheerio"); // You can import NPM packages
const reply = await fetch("https://news.ycombinator.com/");
const replyText = await reply.text();
const $ = await cheerio.load(replyText);
const firstThreadTitle = $(".athing:first-child .titleline > a").first()
.text();
let now = new Date();
let currentHour = now.getHours();
topHNThreadByHour.push(
"Top thread on Hackernews for " + currentHour + ":00 " +
"is: " + firstThreadTitle,
);
await set(
"topHNThreadByHour",
topHNThreadByHour,
);
});
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