2021-09-01 17:33:04 +00:00
|
|
|
var NodeHelper = require("node_helper");
|
|
|
|
const fetch = require("node-fetch");
|
|
|
|
|
|
|
|
var cases = {}
|
|
|
|
|
|
|
|
module.exports = NodeHelper.create({
|
|
|
|
|
|
|
|
socketNotificationReceived: function (notification, region) {
|
2021-10-20 06:35:22 +00:00
|
|
|
|
|
|
|
// get id for passed region
|
|
|
|
fetch("https://c19d.smsvc.net/api/v2/districts?LK_Name="+region)
|
2021-09-01 17:33:04 +00:00
|
|
|
.then(response=>response.json())
|
|
|
|
.then(data=>{
|
2021-10-20 06:35:22 +00:00
|
|
|
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"];
|
2021-09-01 17:33:04 +00:00
|
|
|
|
2021-10-20 06:35:22 +00:00
|
|
|
// send data back to module
|
|
|
|
this.sendSocketNotification("{{MODULE_NAME}}-set_cases", cases)
|
|
|
|
})
|
2021-09-01 17:33:04 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
});
|