Update substitutions automatically

This commit is contained in:
2022-05-03 18:56:00 +02:00
parent 1c8a307815
commit 87e7df5f90
2 changed files with 15 additions and 14 deletions

View File

@ -16,18 +16,8 @@ export class Parser {
this.dsbUser = dsbUser;
this.dsbPassword = dsbPassword;
// setInterval(this.updatePlan, interval);
// this.updatePlan();
(async () => {
const event = await prisma.parseEvent.findFirst({
where: {
succeeded: true,
},
});
const html = fs.readFileSync("plan.html");
const plan = parseSubstitutionPlan(html);
this.insertSubstitutions(plan, event);
})();
setInterval(() => this.updatePlan(), interval);
this.updatePlan();
}
async updatePlan() {
const startedAt = new Date();
@ -51,8 +41,7 @@ export class Parser {
},
});
for (const plan of plans) {
await this.insertSubstitutions(plans, parseEvent);
fs.writeFileSync("tmpfile", JSON.stringify(plan));
await this.insertSubstitutions(plan, parseEvent);
}
} catch (error) {
await prisma.parseEvent.create({
@ -63,6 +52,7 @@ export class Parser {
succeeded: false,
},
});
log("Parser / Main", "Parse event failed: " + error);
}
}
async fetchDSB() {