-
Notifications
You must be signed in to change notification settings - Fork 0
/
aa.ts
34 lines (30 loc) · 1.21 KB
/
aa.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
import { News } from "../types";
import Notifier from "../notifier";
import fetch from "node-fetch";
import * as cheerio from "cheerio";
const NEWS_URL = "http://www.aa.ntnu.edu.tw/news/news.php?class=1101";
async function checkout(): Promise<News[]> {
const res = await fetch(NEWS_URL);
const $ = cheerio.load(await res.text());
const news: News[] = [];
$("table tbody tr").each((idx, elm) => {
const a = $(elm).find("a");
if (a) {
const url = "http://www.aa.ntnu.edu.tw/news/" + a.attr("href");
const title = a.text().trim();
const date = new Date($(elm).find("td:nth-child(2)").text().trim() || 0);
const type = $(elm).find("td:nth-child(1)").text().trim().split(" ");
if (url && title && date) news.push({ id: title, title, url, date, type });
}
});
return news;
}
/** AaNotifier 的資料來源是 https://www.aa.ntnu.edu.tw/news/news.php?class=1101 */
class AaNotifier extends Notifier {
constructor(storage?: News[], size?: number, interval?: number) {
super(storage, size, interval);
this.name = "Academic-Affairs-Notifier";
this.on("check", checkout);
}
}
export default AaNotifier;