Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
Added polling place lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
mheadd committed Mar 19, 2016
1 parent 74f67e0 commit 64e1778
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
3 changes: 2 additions & 1 deletion config/config.js
Expand Up @@ -23,5 +23,6 @@ exports.apis = {
parking_api_url: 'https://api.phila.gov/airport-parking/v1/',
parking_web_url: 'http://www.phl.org/passengerinfo/directionsparking/Pages/parkingGarages.aspx',
flightinfo_url: 'http://flightinfo.phlapi.com/number/',
service_request_url: 'http://api.phila.gov/open311/v2/requests/%id%.json'
service_request_url: 'http://api.phila.gov/open311/v2/requests/%id%.json',
polling_location_url: 'https://zfv58sa9nl.execute-api.us-east-1.amazonaws.com/prod/pollingPlaceLookup'
}
4 changes: 3 additions & 1 deletion intents/intents.js
Expand Up @@ -5,6 +5,7 @@ var flight_info = require('./flight_info');
var train_times = require('./train_times');
var airport_parking = require('./airport_parking');
var train_times = require('./train_times');
var polling_places = require('./polling_places');

module.exports = {
permits: permits,
Expand All @@ -13,5 +14,6 @@ module.exports = {
flight_info: flight_info,
train_times: train_times,
airport_parking: airport_parking,
train_times: train_times
train_times: train_times,
polling_places: polling_places
};
31 changes: 31 additions & 0 deletions intents/polling_places.js
@@ -0,0 +1,31 @@
var utilities = require('../utilities/utilities');
var config = require('../config/config');

exports.respond = function(bot, message, response) {
if(!response.entities.location) {
bot.reply(message, 'You need to specify an address, like this: ```123 some street```');
}
else {
var payload = { address: response.entities.location[0].value };
var url = config.apis.polling_location_url;
utilities.postJson(bot, message, url, settings, payload, buildResonse);
}
}

// Settings for use in rendering user response.
var settings = {};

function buildResonse(bot, message, settings, error, response, body) {
if(!error && response.statusCode == 200) {
var place = body.features[0].attributes;
bot.reply(message, 'Location: ' + place.location);
bot.reply(message, 'Address: ' + place.display_address);
bot.reply(message, 'Parking: ' + utilities.parkingCodeLookup(place.parking));
bot.reply(message, 'Accessibility: ' + utilities.buildingCodeLookup(place.building));
bot.reply(message, 'Map: https://www.google.com/maps/place/' + encodeURIComponent(place.display_address + ', Philadelphia, PA'));

}
else {
bot.reply(message, 'Sorry, I could not look up polling location for that address.');
}
}
32 changes: 30 additions & 2 deletions utilities/utilities.js
Expand Up @@ -4,7 +4,13 @@ var request = require('request');
exports.getJson = function(bot, message, url, settings, callback) {
request(url, function(error, response, body) {
callback(bot, message, settings, error, response, body);
})
});
}

exports.postJson = function(bot, message, url, settings, payload, callback) {
request({method: 'POST', url: url, json: payload}, function(error, response, body) {
callback(bot, message, settings, error, response, body);
});
}

// Titlecase text.
Expand Down Expand Up @@ -34,4 +40,26 @@ exports.formatTime = function (date) {
var ampm = date.getHours() < 12 ? "AM" : "PM";
var formattedTime = hours + ":" + minutes + " " + ampm;
return formattedTime;
}
}

exports.buildingCodeLookup = function(code) {
return building[code];
}

exports.parkingCodeLookup = function(code) {
return parking[code];
}

var building = [];
building['F'] = 'Building Fully Accessible';
building['B'] = 'Building Substantially Accessible';
building['M'] = 'Building Accessibilty Modified';
building['A'] = 'Alternate Entrance';
building['R'] = 'Building Accessible With Ramp';
building['N'] = 'Building Not Accessible';

var parking = [];
parking['N'] = 'No Parking';
parking['G'] = 'General Parking';
parking['L'] = 'Loading Zone';
parking['H'] = 'Handicap Parking';

0 comments on commit 64e1778

Please sign in to comment.