You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
InventoryTracker/inventory_monitor.js

44 lines
1.6 KiB

const fs = require('fs');
const axios = require('axios');
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");
if (fileContents.length>=387){
for (i=0;i<fileContents.length;i++){
line=fileContents[i]
item=line.split(" ")
itemID=item[1]
itemAmt=item[0]
hq=(item[2]!==undefined)?item[2].replace("\r",""):""
itemHQ=hq==="0"?false:true
//console.log(itemID+" x"+itemAmt+" "+(itemHQ))
if(firstLoad){
finalData=[...finalData,{"id":Number(itemID),"amt":Number(itemAmt),"hq":itemHQ}]
}else
if (finalData[i]!==undefined&&(Number.isInteger(finalData[i].id)^Number.isInteger(itemID))){
if (finalData[i].id!=Number(itemID)||finalData[i].amt!==Number(itemAmt)||finalData[i].hq!==Boolean(itemHQ)){
console.log(JSON.stringify(finalData[i])+" !== "+JSON.stringify({"id":Number(itemID),"amt":Number(itemAmt),"hq":Boolean(itemHQ)}))
finalData[i]={"id":Number(itemID),"amt":Number(itemAmt),"hq":Boolean(itemHQ)}
changed=true;
}
}
}
if (changed){
console.log("Changes occurred...")
axios.post("http://projectdivar.com/inventoryData",finalData)
}
firstLoad=false
}
setTimeout(update,1000)
})
}
update()