Last active
August 29, 2015 14:08
-
-
Save pa-w/79fec94db5c79359c444 to your computer and use it in GitHub Desktop.
Código para obtener la disponibilidad de la $estacion de ecobici
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
function getDisponibilidad($estacion) { | |
$ch = curl_init("https://www.ecobici.df.gob.mx/CallWebService/StationBussinesStatus.php"); // Ecobici's endpoint. Returns an HTML. | |
curl_setopt($ch, CURLOPT_POST, true); | |
$data = array('idStation' => $estacion); // idStation set | |
// CURL's options... | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_AUTOREFERER, true); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | |
$s = curl_exec($ch); // gets the HTML for us to parse | |
$r = str_replace("\r\n", "", $s); //flatten | |
$pattern = "/\b[0-9]+\b/"; | |
preg_match_all($pattern, $r, $matches); // magic! | |
return $matches[0]; // array(1 => (bikes available), 2 => (locks available) ) | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment