Skip to content
Snippets Groups Projects
Verified Commit 7b017b0d authored by Erick Hitter's avatar Erick Hitter
Browse files

Reformat to introduce forecast and provide better display

parent e2f385b3
No related branches found
No related tags found
No related merge requests found
......@@ -41,7 +41,7 @@ app.post('/post', function(req, res){
pathname: 'http://api.wunderground.com/api/' + apikey + '/conditions/q/' + req.body.text + format,
});
console.log(parsed_url);
console.log( req.body.text );
request(parsed_url, function (error, response, body) {
if ( error || 200 !== response.statusCode ) {
......@@ -55,19 +55,38 @@ app.post('/post', function(req, res){
var icon_url = conditionData.current_observation.icon_url;
var location = conditionData.current_observation.display_location.full;
var body = {
response_type: "in_channel",
"attachments": [
{
"text": "Location: " + location + "\n"
+ "Temperature: " + temperature + "\n"
+ "Condition: " + weatherCondition,
"image_url": icon_url,
}
]
};
res.send( body );
parsed_url = url.format({
pathname: 'http://api.wunderground.com/api/' + apikey + '/forecast/q/' + req.body.text + format,
});
request( parsed_url, function( error, response, body ) {
// Basic response for the conditions data already obtained
var responseBody = {
"response_type": "in_channel",
"icon": icon_url,
"text": "Forecast",
"attachments": [
{
"text": "Location: " + location + "\n"
+ "Temperature: " + temperature + "\n"
+ "Condition: " + weatherCondition,
"image_url": icon_url,
}
]
};
// If forecast wasn't available, return just the conditions
if ( error || 200 !== response.statusCode ) {
responseBody.attachments[1] = { "text":"Could not retrieve forecast" };
return res.send( responseBody );
}
// Build forecast into a table
res.send( responseBody );
});
});
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment