fixing copilot shit

This commit is contained in:
ryzetech 2023-01-18 17:28:38 +01:00
parent a54c29dbee
commit 6ace967de7

33
app.js
View file

@ -1,27 +1,32 @@
const config = require( "./config.json" ); const config = require("./config.json");
const spaces = require( "./spaces.json" ); const spaces = require("./spaces.json");
const { setInterval } = require( "node:timers/promises" ); const { setInterval } = require("node:timers/promises");
const fetch = require("node-fetch");
const NodeCache = require( "node-cache" ); const NodeCache = require("node-cache");
// const cron = require( "node-cron" );
const jp = require('jsonpath'); const jp = require('jsonpath');
const cache = new NodeCache({ stdTTL: config.checkperiod*3 }); const cache = new NodeCache({ stdTTL: config.checkperiod * 3 });
(async function() { (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..." ); console.log("Checking for spaces...");
for (const space of spaces) { for (const space of spaces) {
console.log( `Checking ${space.id}...` ); 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) { async function checkSpace(space) {
const response = await fetch(space.url); try {
const data = await response.json(); const response = await fetch(space.endpoint);
const data = await response.json();
} catch (error) {
console.error(error);
}
let open; let open;
if (!space.path) { if (!space.path) {