From 636ea6f732f4515f57509441e96fa4c6b88dace1 Mon Sep 17 00:00:00 2001 From: ryzetech Date: Wed, 18 Jan 2023 12:15:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ app.js | 35 +++++++++++++++++++++ config.json | 3 ++ package.json | 8 +++++ spaces.json | 40 +++++++++++++++++++++++ yarn.lock | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 177 insertions(+) create mode 100644 .gitignore create mode 100644 app.js create mode 100644 config.json create mode 100644 package.json create mode 100644 spaces.json create mode 100644 yarn.lock diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4a73542 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +website.js \ No newline at end of file diff --git a/app.js b/app.js new file mode 100644 index 0000000..b809625 --- /dev/null +++ b/app.js @@ -0,0 +1,35 @@ +const config = require( "./config.json" ); +const spaces = require( "./spaces.json" ); + +const { setInterval } = require( "node:timers/promises" ); + +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)) { + console.log( "Checking for spaces..." ); + for (const space of spaces) { + console.log( `Checking ${space.id}...` ); + let o = checkSpace(space); + } + } +}) + +async function checkSpace(space) { + const response = await fetch(space.url); + const data = await response.json(); + let open; + + if (!space.path) { + try { open = data.state.open; } + catch { console.error(`The space ${space.id} is not using the SpaceAPI standard. Please specify a path.`); } + } else { + try { open = (jp.query(data, space.path) == (space.expected ? space.expected : true)); } + catch { console.error(`The space ${space.id} has an invalid JSONPath to the target value. Please use https://jsonpath.com/ to evaluate the path.`); } + } + return open; +} \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..9d433ce --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +{ + "checkperiod": 300 +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..b0b315a --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "axios": "^1.2.3", + "graphql": "^16.6.0", + "node-cache": "^5.1.2", + "node-cron": "^3.0.2" + } +} diff --git a/spaces.json b/spaces.json new file mode 100644 index 0000000..c859498 --- /dev/null +++ b/spaces.json @@ -0,0 +1,40 @@ +[ + { + "name": "UNHB", + "id": "unhb", + "endpoint": "https://keinanschluss.unhb.de/spaceapi.json" + }, + { + "name": "Chaostreff Dortmund", + "id": "ctdo", + "endpoint": "https://status.ctdo.de/api/spaceapi/v13" + }, + { + "name": "Chaospott", + "id": "chaospott", + "endpoint": "https://status.chaospott.de/status.json" + }, + { + "name": "CCC Aachen", + "id": "cccaachen", + "endpoint": "https://status.aachen.ccc.de/api/v0/status/current?public", + "path": "$.changed.status", + "expected": "public" + }, + { + "name": "CCC Köln", + "id": "ccckoeln", + "endpoint": "https://api.koeln.ccc.de" + }, + { + "name": "Hasi", + "id": "hasi", + "endpoint": "https://status.hasi.it/" + }, + { + "name": "Warpzone", + "id": "warpzone", + "endpoint": "https://api.warpzone.ms/status", + "path": "$.tuerOffen" + } +] \ No newline at end of file diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..f4e00e3 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,89 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +asynckit@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" + integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q== + +axios@^1.2.3: + version "1.2.3" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.2.3.tgz#31a3d824c0ebf754a004b585e5f04a5f87e6c4ff" + integrity sha512-pdDkMYJeuXLZ6Xj/Q5J3Phpe+jbGdsSzlQaFVkMQzRUL05+6+tetX8TV3p4HrU4kzuO9bt+io/yGQxuyxA/xcw== + dependencies: + follow-redirects "^1.15.0" + form-data "^4.0.0" + proxy-from-env "^1.1.0" + +clone@2.x: + version "2.1.2" + resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f" + integrity sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w== + +combined-stream@^1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" + integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== + dependencies: + delayed-stream "~1.0.0" + +delayed-stream@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" + integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ== + +follow-redirects@^1.15.0: + version "1.15.2" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" + integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== + +form-data@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" + integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + +graphql@^16.6.0: + version "16.6.0" + resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.6.0.tgz#c2dcffa4649db149f6282af726c8c83f1c7c5fdb" + integrity sha512-KPIBPDlW7NxrbT/eh4qPXz5FiFdL5UbaA0XUNz2Rp3Z3hqBSkbj0GVjwFDztsWVauZUWsbKHgMg++sk8UX0bkw== + +mime-db@1.52.0: + version "1.52.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70" + integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg== + +mime-types@^2.1.12: + version "2.1.35" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a" + integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw== + dependencies: + mime-db "1.52.0" + +node-cache@^5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/node-cache/-/node-cache-5.1.2.tgz#f264dc2ccad0a780e76253a694e9fd0ed19c398d" + integrity sha512-t1QzWwnk4sjLWaQAS8CHgOJ+RAfmHpxFWmc36IWTiWHQfs0w5JDMBS1b1ZxQteo0vVVuWJvIUKHDkkeK7vIGCg== + dependencies: + clone "2.x" + +node-cron@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/node-cron/-/node-cron-3.0.2.tgz#bb0681342bd2dfb568f28e464031280e7f06bd01" + integrity sha512-iP8l0yGlNpE0e6q1o185yOApANRe47UPbLf4YxfbiNHt/RU5eBcGB/e0oudruheSf+LQeDMezqC5BVAb5wwRcQ== + dependencies: + uuid "8.3.2" + +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + +uuid@8.3.2: + version "8.3.2" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" + integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==