Created
March 25, 2018 15:07
-
-
Save vtshah/a8374e2c8c0ecd2b1b61f03fe8b70db5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs') | |
var path = require('path') | |
var _ = require('underscore'); | |
var request = require('request') | |
// Return only base file name without dir | |
function getMostRecentFileName(dir) { | |
var files = fs.readdirSync(dir); | |
// use underscore for max() | |
return _.max(files, function (f) { | |
var fullpath = path.join(dir, f); | |
// ctime = creation time is used | |
// replace with mtime for modification time | |
return fs.statSync(fullpath).ctime; | |
}); | |
} | |
//console.log(getMostRecentFileName(".")) | |
var requestLoop = setInterval(function(){ | |
var recent = getMostRecentFileName(".") | |
console.log(recent) | |
var json = JSON.parse(fs.readFileSync(recent)) | |
console.log(json.people.length) | |
request({ | |
url: "https://hackuva.localtunnel.me/people", | |
method: "POST", | |
timeout: 10000, | |
followRedirect: true, | |
maxRedirects: 10, | |
form : {num: json.people.length, room: "living"} | |
},function(error, response, body){ | |
if(!error && response.statusCode == 200){ | |
console.log('suces!'); | |
}else{ | |
console.log('error' + response.statusCode); | |
} | |
}); | |
}, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment