32 lines
889 B
JavaScript
32 lines
889 B
JavaScript
var NodeHelper = require("node_helper");
|
|
const fetch = require("node-fetch");
|
|
|
|
var cases = {}
|
|
|
|
module.exports = NodeHelper.create({
|
|
|
|
socketNotificationReceived: function (notification, region) {
|
|
|
|
// get id for passed region
|
|
fetch("https://c19d.smsvc.net/api/v2/districts?LK_Name="+region)
|
|
.then(response=>response.json())
|
|
.then(data=>{
|
|
region_id=data[0]["ID"]
|
|
|
|
// get and parse json data from source
|
|
fetch("https://c19d.smsvc.net/api/v2/districts/"+region_id+"/data/last")
|
|
.then(response=>response.json())
|
|
.then(data=>{
|
|
// extract data
|
|
cases.new7_100k = data["Cases_Last_Week_Per_100000"];
|
|
cases.active = data["Cases_Last_Week"];
|
|
cases.total = data["Cases"];
|
|
cases.death = data["Deaths"];
|
|
cases.ts = data["Date"];
|
|
|
|
// send data back to module
|
|
this.sendSocketNotification("{{MODULE_NAME}}-set_cases", cases)
|
|
})
|
|
})
|
|
},
|
|
});
|