Skip to content

Instantly share code, notes, and snippets.

@vtshah
Created March 25, 2018 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vtshah/a8374e2c8c0ecd2b1b61f03fe8b70db5 to your computer and use it in GitHub Desktop.
Save vtshah/a8374e2c8c0ecd2b1b61f03fe8b70db5 to your computer and use it in GitHub Desktop.
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