Skip to content

Commit

Permalink
tweak gauge return to index and output
Browse files Browse the repository at this point in the history
  • Loading branch information
groovecoder committed Jun 8, 2015
1 parent a490f44 commit 32c569a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
17 changes: 13 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,21 @@ app.get('/', function(request, response) {
// The values can change, at some point a person died below grand lake dam, which resulted in them turning it off while they looked for them. To make up for that, Keystone turned on. The charts aren't updated.
// Again, ~6 hours after they say they will generate, riverside will start seeing water.

output = "<h1>";
Promise.all([key(),gauge()]).then(function(res){
if(res[0]==true && res[1]==true){
response.send('Yes there is.');
}else{
response.send('No there isn\'t');
gaugeLevel = res[1];
if (res[1] >= 2.) {
output += "Yes.";
} else if (res[1] >= 1.) {
output += "A little.";
} else if (res[2]) {
console.log(res[2]);
} else {
output += "No.";
}
output += "</h1>";
output += "Guage Level: " + gaugeLevel;
response.send(output);
});
});

Expand Down
11 changes: 2 additions & 9 deletions lib/gauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@ var S = require('string');
// 1. http://waterdata.usgs.gov/usa/nwis/uv?07164500
// #WaterInTheRiver means more than 1' at the gauge, with 2' being a nice looking river.


gauge = function(){
return new Promise(function(resolve, reject){

request('http://waterdata.usgs.gov/usa/nwis/uv?07164500', function (error, response, body) {

if (!error && response.statusCode == 200) {


//Most recent instantaneous value: 7.78 06-06-2015 16:30 CDT

var level = S(body).between("Most recent instantaneous value: "," ")

resolve(level > 2 )

var level = parseFloat(S(body).between("Most recent instantaneous value: "," ").s);
resolve(level)
}else{
reject(error);
}
Expand Down

0 comments on commit 32c569a

Please sign in to comment.