Made first version work
This commit is contained in:
35
main.ts
35
main.ts
@@ -1,6 +1,7 @@
|
||||
import { Mwn, MwnWikitext } from 'npm:mwn'
|
||||
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({
|
||||
@@ -26,6 +27,15 @@ export interface VideoDescription {
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
@@ -33,27 +43,20 @@ 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 file_content = await bot.read(relevantFiles[0])
|
||||
if (file_content.revisions === undefined) {
|
||||
throw new Error("Page has no revisions")
|
||||
}
|
||||
const content = file_content.revisions[0].content
|
||||
if (content === undefined) {
|
||||
throw new Error("Latest revision has no content")
|
||||
}
|
||||
console.log(content)
|
||||
console.dir(bot.Wikitext.parseSections(content)[2])
|
||||
// parseSummary(content, relevantFiles[0])
|
||||
// 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 {
|
||||
|
||||
Reference in New Issue
Block a user