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 { newestStatusGuid } from "https://esm.town/v/ianvph/newestStatusGuid";
import { parseXML } from "https://esm.town/v/stevekrouse/parseXML?v=1";
export async function posthogStatusTracker() {
const statusRSSLink = "https://status.posthog.com/history.rss";
const response = await fetch(statusRSSLink);
const newestEntry =
(await parseXML(await response.text())).rss.channel
.item[0];
console.log(newestEntry);
if (newestEntry.guid == newestStatusGuid) {
return "old status";
}
const properties = {
title: newestEntry.title,
published_date: newestEntry.pubDate,
link: newestEntry.link,
};
const captureData = {
key: phProjectAPIKey,
event: "posthog status update",
properties: properties,
distinct_id: email,
};
postHogAPICapture(captureData);
await set("newestStatusGuid", newestEntry.guid);
return "posthog status update captured";
}