Runs every 1 days
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
45
46
47
48
import { email } from "https://esm.town/v/std/email?v=9";
import { fetch } from "https://esm.town/v/std/fetch?v=4";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
import { hnJobToText } from "https://esm.town/v/yeskunall/hnJobToText?v=2";
const hnEmail = async ({
posts,
footer,
}: {
posts: any[];
footer?: boolean;
}) => {
const footer_ = [
"Unsubscribe by clearing your interval here: https://val.town/@me.intervals",
];
const postsAsText = await Promise.all(
posts.map(hnJobToText),
);
const subject = `πŸ‘¨πŸ½β€πŸ’» (${posts.length}) jobs found`;
const text = [
postsAsText.join("\n\n"),
...(footer === false ? [] : footer_),
].join("\n\n");
return { subject, text };
};
// Get upto (200) of the latest jobs posted on HN
export async function hnLatestJobs() {
const jobStories: Number[] = await fetch(
"https://hacker-news.firebaseio.com/v0/jobstories.json",
).then((res) => res.json());
const posts = await Promise.all(
jobStories.map(async (id) => {
return await fetchJSON(
`https://hacker-news.firebaseio.com/v0/item/${id}.json`,
);
}),
);
const { subject, text } = await hnEmail({
posts,
});
return email({ subject, text });
}
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 27, 2023