Skip to content

Instantly share code, notes, and snippets.

@jmolivas
Created November 15, 2012 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmolivas/4081351 to your computer and use it in GitHub Desktop.
Save jmolivas/4081351 to your computer and use it in GitHub Desktop.
PHP Goutte BWT reader
header('Content-Type: text/xml');
require_once __DIR__.'/../goutte.phar';
include __DIR__."/../include/FeedTypes.php";
use Goutte\Client;
$client = new Client();
$crawler = $client->request('GET', 'http://apps.cbp.gov/bwt/');
$locations = array ( "CalexicoEast", "CalexicoWest" );
$language = array( "CalexicoEast" => "Mexicali II", "CalexicoWest" => "Mexicali Centro",
"At" => "", " PST" => ", " , "no delay" => "0 min ", "delay" => "espera, ",
"lane(s) open" => "líneas abiertas ", "Lanes Closed" => " Lineas Cerradas ",
"min"=>"min ");
$items = array();
$crawler->filter('table[class=basic_text] > tr td[headers=pc_id]')->each(function ($node, $i) use ($locations, $language, &$items) {
if ( in_array( trim($node->nodeValue), $locations ) ) {
$nodeValue = str_replace(array_keys($language), array_values($language), $node->parentNode->nodeValue );
$nodeValues = explode( "\n" , str_replace( "\r", "", $nodeValue) );
if ( isset($nodeValues[7]) && $nodeValues[7]!="N/A")
$items[] = array ( 'title' => $nodeValues[0] . " - Vehiculos", 'link' => 'http://apps.cbp.gov/bwt/', 'description' => $nodeValues[7] );
if ( isset($nodeValues[8]) && $nodeValues[8]!="N/A")
$items[] = array ( 'title' => $nodeValues[0] . " - Ready Lane", 'link' => 'http://apps.cbp.gov/bwt/', 'description' => $nodeValues[8] );
if ( isset($nodeValues[9]) && $nodeValues[9]!="N/A")
$items[] = array ( 'title' => $nodeValues[0] . " - SENTRI", 'link' => 'http://apps.cbp.gov/bwt/', 'description' => $nodeValues[9] );
if ( isset($nodeValues[11]) && $nodeValues[11]!="N/A")
$items[] = array ( 'title' => $nodeValues[0] . " - Peatonal", 'link' => 'http://apps.cbp.gov/bwt/', 'description' => $nodeValues[11] );
}
});
$rssFeed = new RSS2FeedWriter();
//Setting the channel elements
//Use wrapper functions for common channel elements
$rssFeed->setTitle('ZonaLider');
$rssFeed->setLink('http://rss.zonalider.com/bwt/');
$rssFeed->setDescription('ZonaLider RSS Channel');
//Use core setChannelElement() function for other optional channels
$rssFeed->setChannelElement('language', 'es-MEX');
$rssFeed->setChannelElement('pubDate', date(DATE_RSS, time()));
foreach ($items as &$item ) {
$rssItem = $rssFeed->createNewItem();
$rssItem->setTitle($item['title']);
$rssItem->setLink($item['link']);
$rssItem->setDate(time());
$rssItem->setDescription($item['description']);
$rssFeed->addItem($rssItem);
}
echo $rssFeed->generateFeed();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment