-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
74 lines (63 loc) · 1.63 KB
/
main.ts
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// A script wich converts the news items from the GST portal as a rss feed
// License: GPLv3
import { Atom } from "jsr:@feed/feed";
let fileName = "feed.xml";
const atomFeed = new Atom({
title: "GST News & Updates",
description: "News and updates from the GST Portal",
link: "https://www.gst.gov.in/",
authors: [
{
name: "GST India",
email: "test@example.org",
},
],
updated: new Date(),
id: "https://www.gst.gov.in",
});
// return date as per atom spec
function formatDate(d: string) {
const date = d.split("/").reverse().join("-");
return new Date(date);
}
async function fetchPayload() {
console.info("Fetching news from the GST portal");
const r = await fetch("https://www.gst.gov.in/fomessage/newsupdates");
const data = await r.json();
if (r.status != 200) {
console.error("Failed to fetch the data");
Deno.exit(1);
}
console.info("Generating feeds ...");
for (const item of data.data) {
atomFeed.addItem({
title: `[${item.module}] ${item.title}`,
link: `https://www.gst.gov.in/newsandupdates/read/${item.id}`,
id: `${item.id}`,
updated: formatDate(item.date),
summary: item.title,
content: {
body: item.content,
type: "html",
},
});
}
// export to a file
try {
Deno.writeTextFileSync(`${fileName}`, atomFeed.build());
console.log(`Saved to ${fileName}`);
} catch (e) {
console.error(`failed to save file: ${fileName}\n${e}`);
Deno.exit(1);
}
}
function main() {
const args = Deno.args;
if (args.length == 1) {
fileName = args[0];
fetchPayload();
return;
}
fetchPayload();
}
main();