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
import { fetch } from "https://esm.town/v/std/fetch";
import { set } from "https://esm.town/v/std/set?v=11";
import { postHogAPICapture } from "https://esm.town/v/ianvph/postHogAPICapture";
import { email } from "https://esm.town/v/ianvph/email";
import { phProjectAPIKey } from "https://esm.town/v/ianvph/phProjectAPIKey";
import { newestBlogLink } from "https://esm.town/v/ianvph/newestBlogLink";
import { parseXML } from "https://esm.town/v/stevekrouse/parseXML?v=1";
export async function blogRSSTracker() {
// gets newest blog from rss feed
const blogRSSLink = "https://posthog.com/rss.xml";
const response = await fetch(blogRSSLink);
const newestEntry =
(await parseXML(await response.text())).rss.channel
.item[0];
// checks if different from last blog captured
if (newestEntry.link == newestBlogLink) {
return "old blog";
}
// captures event to posthog if so
const properties = {
title: newestEntry.title,
published_date: newestEntry.pubDate,
author: newestEntry["dc:creator"],
link: newestEntry.link,
};
const captureData = {
key: phProjectAPIKey,
event: "new blog published",
properties: properties,
distinct_id: email,
};
postHogAPICapture(captureData);
await set("newestBlogLink", newestEntry.link);
return "new blog captured";
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
v26
October 23, 2023