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.
40 lines
1.2 KiB
40 lines
1.2 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");
|
|
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":Boolean(itemHQ)},...finalData]
|
|
}else
|
|
if (finalData[i]!==undefined){
|
|
if (finalData[i].id!==itemID||finalData[i].amt!==itemAmt||finalData[i].hq!==Boolean(itemHQ)){
|
|
finalData[i]={"id":itemID,"amt":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() |