Improved layout, added warnings to result page
This commit is contained in:
23
main.ts
23
main.ts
@@ -1,7 +1,7 @@
|
||||
import { Mwn, RecentChange } from 'npm:mwn'
|
||||
import process, { title } from "node:process";
|
||||
import { parseSummary } from "./parse.ts";
|
||||
import { bucketEvents, writeSection } from "./write.ts";
|
||||
import { bucketEvents, writeSections } from "./write.ts";
|
||||
|
||||
async function getWorkshopVideos(bot: Mwn): Promise<string[]> {
|
||||
const response = await bot.request({
|
||||
@@ -29,13 +29,20 @@ export interface VideoDescription {
|
||||
notes: string
|
||||
path: string
|
||||
title: string
|
||||
nags: string[]
|
||||
}
|
||||
|
||||
async function fetchPages(pages: string[], bot: Mwn): Promise<VideoDescription[]> {
|
||||
const d = await Promise.allSettled(pages.map(async (v) =>
|
||||
parseSummary(await new bot.Page(v).text(), v)
|
||||
))
|
||||
|
||||
d.map((v, index) => ({ r: v, source: pages[index] })).filter((v): v is { source: string, r: PromiseRejectedResult } => v.r.status === "rejected").forEach(
|
||||
v => console.warn(`Error parsing ${v.source}: ${v.r.reason}`
|
||||
))
|
||||
|
||||
return d.filter(v => v.status === "fulfilled").map(v => v.value)
|
||||
|
||||
}
|
||||
|
||||
function sleep(ms: number): Promise<void> {
|
||||
@@ -45,6 +52,16 @@ function sleep(ms: number): Promise<void> {
|
||||
async function watchdog(bot: Mwn, onChange: (paths: string[]) => Promise<void>) {
|
||||
let last_change: string | undefined = undefined;
|
||||
|
||||
let heartbeat_count = 0;
|
||||
const heartbeat_count_max = 60;
|
||||
|
||||
const heartbeat = () => {
|
||||
heartbeat_count += 1
|
||||
if (heartbeat_count >= heartbeat_count_max) {
|
||||
heartbeat_count = 0;
|
||||
console.log(new Date(), "Heartbeat")
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const { last_change: l, new_file_changes } = await queryChanges(bot, last_change);
|
||||
@@ -53,7 +70,7 @@ async function watchdog(bot: Mwn, onChange: (paths: string[]) => Promise<void>)
|
||||
console.log(new_file_changes.length, "changes")
|
||||
await onChange(new_file_changes.map(v => v.title))
|
||||
}
|
||||
console.log(new Date(), "Heartbeat")
|
||||
heartbeat()
|
||||
await sleep(30000);
|
||||
}
|
||||
}
|
||||
@@ -94,7 +111,7 @@ async function main() {
|
||||
await watchdog(bot, async (paths) => {
|
||||
const relevantFiles = await getWorkshopVideos(bot)
|
||||
const d = await fetchPages(relevantFiles, bot)
|
||||
const t = writeSection(bucketEvents(d))
|
||||
const t = writeSections(bucketEvents(d))
|
||||
const response = await bot.save(title, "{{TOC|limit=3}}\n\n" + t, 'Triggered by changes to ' + paths.map(v => "[[" + v + "]]").join(", "));
|
||||
console.log(response)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user