Skip to content

Instantly share code, notes, and snippets.

@pa-w
Last active August 29, 2015 14:08
Show Gist options
  • Save pa-w/79fec94db5c79359c444 to your computer and use it in GitHub Desktop.
Save pa-w/79fec94db5c79359c444 to your computer and use it in GitHub Desktop.
Código para obtener la disponibilidad de la $estacion de ecobici
<?
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