Tracks updates from a file and reports if changes occur
This commit is contained in:
commit
6f66b6a5ef
38
inventory_monitor.js
Normal file
38
inventory_monitor.js
Normal file
@ -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()
|
BIN
node_modules/.cache/default-development/0.pack
generated
vendored
Normal file
BIN
node_modules/.cache/default-development/0.pack
generated
vendored
Normal file
Binary file not shown.
BIN
node_modules/.cache/default-development/index.pack
generated
vendored
Normal file
BIN
node_modules/.cache/default-development/index.pack
generated
vendored
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user