Browse Source

Create status JSON

Compare fetched titles with ones in CSV to get status. Include update
time and server uptime.
master
Kevin Mok 5 years ago
parent
commit
bc0e55187a
Signed by: Kevin-Mok GPG Key ID: AEA75288DC135CF5
  1. 7
      csv-to-json.js
  2. 2033
      package-lock.json
  3. 3
      package.json
  4. 2
      server-pages-test.csv
  5. 18
      server-pages.csv
  6. 49
      server-status.js
  7. 34
      yarn.lock

7
csv-to-json.js

@ -1,7 +0,0 @@
const csvFilePath='server-apps.csv'
const csv=require('csvtojson')
csv()
.fromFile(csvFilePath)
.then((jsonObj)=>{
console.log(JSON.stringify(jsonObj));
})

2033
package-lock.json
File diff suppressed because it is too large
View File

3
package.json

@ -6,6 +6,7 @@
"author": "Kevin Mok", "author": "Kevin Mok",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"csvtojson": "^2.0.10"
"csvtojson": "^2.0.10",
"url-metadata": "^2.4.0"
} }
} }

2
server-pages-test.csv

@ -0,0 +1,2 @@
shortUrl,url,siteTitle,description,repo,repoUrl
kevin-mok.com,https://kevin-mok.com," Kevin Mok ","Personal site (this site).",Kevin-Mok/my-site,https://git.kevin-mok.com/Kevin-Mok/my-site

18
server-pages.csv

@ -1,9 +1,9 @@
status,shortUrl,url,siteTitle,description,repo,repoUrl
up,kevin-mok.com,https://kevin-mok.com,"Kevin Mok","Personal site (this site).",Kevin-Mok/my-site,https://git.kevin-mok.com/Kevin-Mok/my-site
up,git.kevin-mok.com,https://git.kevin-mok.com,"Kevin Mok's Gitea","Lightweight Git server.",go-gitea/gitea,https://github.com/go-gitea/gitea
up,cal.khkm.tk,https://cal.khkm.tk,"Baïkal server","CalDAV/CardDAV server.",sabre-io/Baikal,https://github.com/sabre-io/Baikal
up,matrix.ataraxy.tk,https://matrix.ataraxy.tk/.well-known/matrix/server,"","Matrix chat server (only accessible through Riot client).",matrix-org/synapse,https://github.com/matrix-org/synapse
up,mnpd.gq,https://mnpd.gq/test,"test","Minimalistic live web notepad.",pereorga/minimalist-web-notepad,https://github.com/pereorga/minimalist-web-notepad
up,pste.gq,https://pste.gq,"hastebin","Pastebin.",seejohnrun/haste-server,https://github.com/seejohnrun/haste-server
up,smol.gq,https://smol.gq,"Kevin's URL Shortener","URL shortener.",132ikl/liteshort,https://github.com/132ikl/liteshort
up,twem.tk,https://twem.tk,"Twitch Emote Links","Twitch emotes (for Matrix chat server).",,
shortUrl,url,siteTitle,description,repo,repoUrl
kevin-mok.com,https://kevin-mok.com," Kevin Mok ","Personal site (this site).",Kevin-Mok/my-site,https://git.kevin-mok.com/Kevin-Mok/my-site
git.kevin-mok.com,https://git.kevin-mok.com,"Kevin Mok's Gitea","Lightweight Git server.",go-gitea/gitea,https://github.com/go-gitea/gitea
cal.khkm.tk,https://cal.khkm.tk,"Baïkal server","CalDAV/CardDAV server.",sabre-io/Baikal,https://github.com/sabre-io/Baikal
matrix.ataraxy.tk,https://matrix.ataraxy.tk/.well-known/matrix/server,,"Matrix chat server. Only accessible through Riot client.",matrix-org/synapse,https://github.com/matrix-org/synapse
mnpd.gq,https://mnpd.gq/test,"test","Minimalistic live web notepad.",pereorga/minimalist-web-notepad,https://github.com/pereorga/minimalist-web-notepad
pste.gq,https://pste.gq,"hastebin","Pastebin.",seejohnrun/haste-server,https://github.com/seejohnrun/haste-server
smol.gq,https://smol.gq,"Kevin's URL Shortener","URL shortener.",132ikl/liteshort,https://github.com/132ikl/liteshort
taskd.khkm.tk,taskd.khkm.tk:53589,,"Taskwarrior (task manager) server. No web interface.",GothenburgBitFactory/taskserver,https://github.com/GothenburgBitFactory/taskserver

49
server-status.js

@ -0,0 +1,49 @@
const urlMetadata = require('url-metadata')
const csv = require('csvtojson')
const log = console.log
const { spawnSync } = require( 'child_process' ),
// uptime = spawnSync( 'uptime', [ '-p' ] )
uptime = spawnSync( 'uptime', [ '-s' ] )
const csvFilePath = 'server-pages.csv'
// const csvFilePath = 'server-pages-test.csv'
const checkIfTitleMatches = obj => {
return urlMetadata(obj['url']).then(metadata => { // success handler
if (metadata.title == obj['siteTitle']) {
// log(obj['shortUrl'])
obj['status'] = 'up'
} else {
// console.log(metadata)
obj['status'] = 'down'
}
return true
},
error => { // failure handler
console.log(error)
})
}
const updateSiteStatus = json => {
const promiseArray = []
json.forEach(async function (obj) {
if (obj['siteTitle'] != '') {
promiseArray.push(checkIfTitleMatches(obj))
} else{
obj['status'] = 'up'
}
})
return promiseArray
}
csv().fromFile(csvFilePath).then(async function (json) {
Promise.all(updateSiteStatus(json)).then(results => {
const statusJson = {
"sites": json,
"updateTime": Date.now(),
"upSince": `${uptime.stdout.toString()}`.replace(/\n/g, ''),
}
// console.log(JSON.stringify(statusJson))
console.log(JSON.stringify(statusJson, null, 2))
})
})

34
yarn.lock

@ -1,34 +0,0 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
bluebird@^3.5.1:
version "3.5.5"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.5.tgz#a8d0afd73251effbbd5fe384a77d73003c17a71f"
integrity sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==
csvtojson@^2.0.10:
version "2.0.10"
resolved "https://registry.yarnpkg.com/csvtojson/-/csvtojson-2.0.10.tgz#11e7242cc630da54efce7958a45f443210357574"
integrity sha512-lUWFxGKyhraKCW8Qghz6Z0f2l/PqB1W3AO0HKJzGIQ5JRSlR651ekJDiGJbBT4sRNNv5ddnSGVEnsxP9XRCVpQ==
dependencies:
bluebird "^3.5.1"
lodash "^4.17.3"
strip-bom "^2.0.0"
is-utf8@^0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72"
integrity sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=
lodash@^4.17.3:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
strip-bom@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-2.0.0.tgz#6219a85616520491f35788bdbf1447a99c7e6b0e"
integrity sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=
dependencies:
is-utf8 "^0.2.0"
Loading…
Cancel
Save