fixing copilot shit

This commit is contained in:
ryzetech 2023-01-18 17:28:38 +01:00
parent a54c29dbee
commit 6ace967de7
1 changed files with 19 additions and 14 deletions

15
app.js
View File

@ -2,26 +2,31 @@ const config = require( "./config.json" );
const spaces = require("./spaces.json");
const { setInterval } = require("node:timers/promises");
const fetch = require("node-fetch");
const NodeCache = require("node-cache");
// const cron = require( "node-cron" );
const jp = require('jsonpath');
const cache = new NodeCache({ stdTTL: config.checkperiod * 3 });
(async function () {
for await (const time of setInterval(config.checkperiod*1000)) {
for await (const time of setInterval(config.checkperiod * 10)) {
console.log("Checking for spaces...");
for (const space of spaces) {
console.log(`Checking ${space.id}...`);
let o = checkSpace(space);
let o = await checkSpace(space);
console.log(`Space ${space.id} is ${o ? "open" : "closed"}`);
}
}
})
})();
async function checkSpace(space) {
const response = await fetch(space.url);
try {
const response = await fetch(space.endpoint);
const data = await response.json();
} catch (error) {
console.error(error);
}
let open;
if (!space.path) {