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
Branches
Tags
No related merge requests found
...@@ -41,7 +41,7 @@ app.post('/post', function(req, res){ ...@@ -41,7 +41,7 @@ app.post('/post', function(req, res){
pathname: 'http://api.wunderground.com/api/' + apikey + '/conditions/q/' + req.body.text + format, 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) { request(parsed_url, function (error, response, body) {
if ( error || 200 !== response.statusCode ) { if ( error || 200 !== response.statusCode ) {
...@@ -55,19 +55,38 @@ app.post('/post', function(req, res){ ...@@ -55,19 +55,38 @@ app.post('/post', function(req, res){
var icon_url = conditionData.current_observation.icon_url; var icon_url = conditionData.current_observation.icon_url;
var location = conditionData.current_observation.display_location.full; var location = conditionData.current_observation.display_location.full;
var body = { parsed_url = url.format({
response_type: "in_channel", pathname: 'http://api.wunderground.com/api/' + apikey + '/forecast/q/' + req.body.text + format,
"attachments": [ });
{
"text": "Location: " + location + "\n" request( parsed_url, function( error, response, body ) {
+ "Temperature: " + temperature + "\n" // Basic response for the conditions data already obtained
+ "Condition: " + weatherCondition, var responseBody = {
"image_url": icon_url, "response_type": "in_channel",
} "icon": icon_url,
] "text": "Forecast",
}; "attachments": [
{
res.send( body ); "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