-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
70 lines (59 loc) · 1.96 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* Washington Dulles Security Wait Time API.
*
* Simple security wait time API that scrapes the MWAA mobile web
* page and reports on how long in minutes you can expect to spend
* passing through security at each of the two checkpoints.
*
* Author: Simon Prickett (http://simonprickett.github.io/)
*
* You are free to use this and modify it as you like, but I'd be
* interested in knowing what anyone does with it.
*
*/
// Go get the page
$iadUrl = 'http://www.mwaa.com/mobile/IAD/IADWaitTime.html';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $iadUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$pageHtml = curl_exec($ch);
curl_close($ch);
// Now parse it
$dom = new DOMDocument();
$dom->loadHTML($pageHtml);
// Get the wait times
$eastWait = -1;
$westWait = -1;
$spans = $dom->getElementsByTagName('span');
foreach($spans as $span) {
$pos = strpos($span->nodeValue, 'minute');
if ($pos > 0) {
// -2 gets rid of the
$waitTime = trim(substr($span->nodeValue, 0, $pos - 2));
if ($eastWait === -1) {
$eastWait = $waitTime;
} else {
$westWait = $waitTime;
}
}
}
// Get the last updated time
$paras = $dom->getElementsByTagName('p');
$lastUpdated = '';
foreach($paras as $para) {
if (strpos($para->nodeValue, '* Last updated at') !== false) {
// 19 = length of * Last updated at plus 2 for the
$lastUpdated = trim(substr($para->nodeValue, 19));
break;
}
}
// Time zone
$dt = new DateTime($lastUpdated, new DateTimeZone('America/New_York'));
$jsonOut = '{ "airports": [ { "iata": "IAD", "name" : "Washington Dulles", "lastUpdated": "' . $lastUpdated . '", "lastUpdatedTimestamp": ' . $dt->getTimestamp() . ', "checkPoints": [ { "name": "East", "wait" : ' . $eastWait . ' }, { "name": "West", "wait" : ' . $westWait . ' } ] } ] }';
// Send the response with appropriate content type
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
print $jsonOut;
?>