taitcha / tsa-mashup Goto Github PK
View Code? Open in Web Editor NEWCombines TSA Security Checkpoint Wait Times API and Google Maps Distance Matrix API to estimate when you should leave for the airport.
License: BSD 2-Clause "Simplified" License
Combines TSA Security Checkpoint Wait Times API and Google Maps Distance Matrix API to estimate when you should leave for the airport.
License: BSD 2-Clause "Simplified" License
TSA-Mashup Readme *** AUTHOR Tait Chamberlain [email protected] http://www.taitcha.net *** DESCRIPTION This project combines the TSA Security Checkpoint Wait Times API and Google Maps Distance Matrix API to estimate when you should leave for the airport. It calls Google to calculate predicted travel time based on start address and airport, checks current TSA checkpoint wait times at that airport, and provides an estimated travel time based on both factors, as well as user variables such as whether they have TSA Precheck and are pessimistic. It has some useful classes for anyone looking to play around with TSA SCWT API data in their own projects. *** REQUIREMENTS In order to run the code as-is, you’ll need to get your own Google Maps Distance Matrix API Key, which you can apply for here: https://developers.google.com/maps/documentation/distance-matrix/ Written for Python 2.7.10 *** FILES INCLUDED tsa-mashup.py This file is the main program. cached_results.txt Stores the cached pickled responses for running the program offline. Responses from both Google and the TSA APIs are returned in JSON. apcp.xml Stores the TSA Airport metadata necessary to make sense of the data returned from the TSA Security Checkpoint Wait Times API. The program parses the XML and loads up a dictionary of TSAairport class instances to combine with returned API data. readme.txt Readme file for the program. *** PACKAGES NEEDED # Unittest used for testing purposes import unittest # Json used to parse REST API request results import json # Requests used to pull REST API results import requests # Pickle used for caching REST API request results import pickle # ET used for parsing TSA Metadata XML import xml.etree.ElementTree as ET # Math used for rounding up import math # String used for uppercase conversions import string *** APIS USED The MyTSA Web Service API def GetTSAWaitTimes(airportCode): """ Returns data from the TSA Wait Times API for a particular airport shortcode. :param airportCode: 3-letter shortcode of airport :return: Returns the full parsed json data from TSA Wait Times API """ base_url = "http://apps.tsa.dhs.gov/MyTSAWebService/GetTSOWaitTimes.ashx" Documentation: https://www.dhs.gov/mytsa-api-documentation Needs the airport metadata contained here to make sense of things: http://www.tsa.gov/data/apcp.xml Note: It returns the last 25 wait times, but these can be for any checkpoint and are not necessarily reported regularly. Also, the wait times are in 10-minute increments, with 0 indicating no wait, and 1 indicating 1-10 minute wait, etc. They do not make this very clear. Valid parameters include ap (airport), output (json), st (state), pc (TSA PreCheck line), al (airline). The airport parameter is required. Google Distance Matrix API def GetDistance(origin, airportCode, key, units="imperial"): """ Gets and returns the processed json response from the Google Distance Matrix API :param origin: Where the trip to the airport starts :param airportCode: 3-letter shortcode of airport :param key: Google API key :param units: Measurement return from Google API, can also be metric :return: Returns the processed json response """ base_url = "https://maps.googleapis.com/maps/api/distancematrix/json" Documentation: https://developers.google.com/maps/documentation/distance-matrix/ Requires a key which I've already secured, and allows up to 2500 requests per month for free, which should be sufficient for the project. Required parameters are origins, destinations, and key (API key). There are many optional parameters, including transit_mode and traffic_model. Note that distances are returned in meters and trip times in seconds, regardless of imperial or metric parameters (this only affects the text values returned). *** LICENSE BSD 2
Thanks for sharing your code. I'd love to use it but it seems like the TSA API is deprecated. Do you have any suggestions on alternatives?
See below for the base_url that's now deprecated and mentioned in the code: http://apps.tsa.dhs.gov/MyTSAWebService/GetTSOWaitTimes.ashx
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.