Tracks updates from a file and reports if changes occur

master
sigonasr2 2 years ago
commit 6f66b6a5ef
  1. 38
      inventory_monitor.js
  2. BIN
      node_modules/.cache/default-development/0.pack
  3. BIN
      node_modules/.cache/default-development/index.pack

@ -0,0 +1,38 @@
const fs = require('fs');
console.log("Hello!")
finalData=[]
firstLoad=true
function update(){
changed=false
fs.readFile("C:\\Users\\sigon\\Documents\\memory",
(err,data)=>{
var fileContents = data.toString().split("\n");
for (i=0;i<fileContents.length;i++){
line=fileContents[i]
item=line.split(" ")
itemID=item[1]
itemAmt=item[0]
itemHQ=item[2]
//console.log(itemID+" x"+itemAmt+" "+(itemHQ?"":"HQ"))
if(firstLoad){
finalData=[{"id":itemID,"amt":itemAmt,"hq":itemHQ},...finalData]
}else
if (finalData[i]!==undefined){
if (finalData[i].id!==itemID||finalData[i].amt!==itemAmt||finalData[i].hq!==itemHQ){
finalData[i]={"id":itemID,"amt":itemAmt,"hq":itemHQ}
changed=true;
}
}
}
if (changed){
console.log("Changes occurred...")
}
firstLoad=false
setTimeout(update,1000)
})
}
update()

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save