Initial monorepo: readin, sensorapi, noise (Node22, npm ci, axios1.x, i18next-fs-backend)

This commit is contained in:
rxf
2026-07-25 11:35:41 +00:00
commit 2df1f79617
97 changed files with 13547 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
import axios from 'axios'
import * as fs from 'fs'
import { logit, logerror} from'./logit.js'
import { DateTime } from 'luxon'
const API_URL = 'https://api.sensor.community/static/v1/data.json'; // URL to API on 'luftdaten.info'
const SAVE_NAME = './data/aktdata.json'; // filename for actual data
let LIVE = process.env.LIVE || 'true'
export let statistics = {};
export const doReadfromAPI = async () => {
logit(`LIVE = ${LIVE}`)
let start = DateTime.now()
let data = []
if (LIVE === 'true') {
logit(`Start Reading from API`)
let body
for(let count = 1; count <= 3; count++) {
try {
logit(`Try - ${count}`)
let ret = await axios(API_URL, {timeout: 10000})
if (ret.status != 200) {
continue
}
data = ret.data
saveDatatoFile(SAVE_NAME, JSON.stringify(data))
break
} catch (e) {
logerror(`doReadfromAPI ${e}`)
}
}
} else {
logit('Start using data on disk')
data = readDatafromFile(SAVE_NAME)
}
statistics.readInTime = start.diffNow('seconds').toObject().seconds * -1
statistics.entries = data.length
logit(`ReadIn-Time: ${statistics.readInTime} sec`)
return data
}
// die Daten in eimnr Datei zwischenspeichern
function saveDatatoFile(fn, data) {
fs.writeFileSync(fn, data)
}
// Daten wieder vom File lesen
function readDatafromFile(fn) {
return JSON.parse(fs.readFileSync(fn))
}