From 6ace967de75a0792c29f288b1364a06ca34d4b57 Mon Sep 17 00:00:00 2001 From: ryzetech Date: Wed, 18 Jan 2023 17:28:38 +0100 Subject: [PATCH] fixing copilot shit --- app.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/app.js b/app.js index b809625..478620e 100644 --- a/app.js +++ b/app.js @@ -1,27 +1,32 @@ -const config = require( "./config.json" ); -const spaces = require( "./spaces.json" ); +const config = require("./config.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 cron = require( "node-cron" ); +const NodeCache = require("node-cache"); const jp = require('jsonpath'); -const cache = new NodeCache({ stdTTL: config.checkperiod*3 }); +const cache = new NodeCache({ stdTTL: config.checkperiod * 3 }); -(async function() { - for await (const time of setInterval(config.checkperiod*1000)) { - console.log( "Checking for spaces..." ); +(async function () { + 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); + console.log(`Checking ${space.id}...`); + let o = await checkSpace(space); + console.log(`Space ${space.id} is ${o ? "open" : "closed"}`); } } -}) +})(); async function checkSpace(space) { - const response = await fetch(space.url); - const data = await response.json(); + try { + const response = await fetch(space.endpoint); + const data = await response.json(); + } catch (error) { + console.error(error); + } let open; if (!space.path) {