68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import { Mwn } from 'npm:mwn'
|
|
import process from "node:process";
|
|
import { parseSummary } from "./parse.ts";
|
|
import { bucketEvents, writeSection } from "./write.ts";
|
|
|
|
async function getWorkshopVideos(bot: Mwn): Promise<string[]> {
|
|
const response = await bot.request({
|
|
action: 'query',
|
|
list: 'allimages',
|
|
aiprefix: 'WCS ', // Search prefix
|
|
ailimit: 'max', // Maximum number of results
|
|
});
|
|
|
|
if (response.query === undefined) {
|
|
throw new Error("Did not receive response to file query")
|
|
}
|
|
|
|
// Extract and print the file titles
|
|
return response.query.allimages.map(function (image: { title: string }) { return image.title });
|
|
}
|
|
|
|
export interface VideoDescription {
|
|
teachers: string[]
|
|
location: string
|
|
event: string
|
|
level: string
|
|
date: string
|
|
patterns: string
|
|
notes: string
|
|
path: string
|
|
title: 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)
|
|
))
|
|
return d.filter(v => v.status === "fulfilled").map(v => v.value)
|
|
}
|
|
|
|
|
|
async function main() {
|
|
const bot = new Mwn({
|
|
apiUrl: 'https://dancing.thasky.one/api.php',
|
|
username: process.env.BOTNAME,
|
|
password: process.env.BOTPW,
|
|
userAgent: 'mwn bot',
|
|
});
|
|
|
|
try {
|
|
await bot.login();
|
|
// const relevantFiles = await getWorkshopVideos(bot)
|
|
// const d = await fetchPages(relevantFiles, bot)
|
|
// await Deno.writeTextFile("./descriptions.json", JSON.stringify(d));
|
|
const d = JSON.parse(await Deno.readTextFile('./descriptions.json'));
|
|
const t = writeSection(bucketEvents(d))
|
|
const response = await bot.save('Video Description (Automated)', "{{TOC|limit=3}}\n\n" + t, 'Generated descriptions');
|
|
console.log(response)
|
|
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
} finally {
|
|
await bot.logout();
|
|
}
|
|
}
|
|
|
|
main();
|