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
import { blob } from "https://esm.town/v/std/blob";
import { email } from "https://esm.town/v/std/email";
import axios from "npm:axios";
import { parseStringPromise } from "npm:xml2js";
export default async function queryNewFeed() {
const user = Deno.env.get("HAW_USER");
const hash = Deno.env.get("HAW_HASH");
const exploredBefore = (await blob.getJSON("HAW_FEED") || []) as FeedItem[];
const uri =
`https://myhaw.haw.tuhh.de/qisserver/pages/cs/sys/portal/feed/portalMessagesFeed.faces?user=${user}&hash=${hash}`;
const allItems = await axios.get<string>(uri)
.then(res => {
console.log("length", res.data.length);
return res;
})
.then(res => parseStringPromise(res.data))
.then((data): FeedItem[] =>
data["rss"]["channel"][0]["item"]
.map((d): FeedItem => ({ title: d.title.join(", "), pubDate: d.pubDate[0] }))
);
const newItems = allItems.filter((item: FeedItem) =>
!exploredBefore.some(i => i.title === item.title && i.pubDate === item.pubDate)
);
if (newItems.length) {
console.log("Alert - New Feed found!");
await email({
subject: "Neuer MyHAW-Feed",
text: newItems.map(({ title, pubDate }): string => `${title} am ${pubDate}`).join("\n"),
});
await blob.setJSON("HAW_FEED", allItems);
}
}
type FeedItem = {
title: string;
pubDate: string;
};
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!
July 22, 2024