Do you like Unix Pipes?
Do you deal with web services?
Have you ever wished that you could pass the output of multiple web services through a unix pipe?
VoilĂ : pipes.yahoo.com
VoilĂ : pipes.yahoo.com
(You need a Yahoo! Id)
source: your data source, similar to cat or echo.operator: anything that operates on data.pipe: a pipe of data from an operator or source to an operator or destination, same as |.output: the last element in your pipe, this returns data to the user.Part I: Creating Pipes using the UI
Let Pipes figure out the feed URL
Let Pipes figure out the feed URL
(use the Fetch Site Feed source)
limit it to 5 items only
limit it to 5 items only
(use Truncate)
Limit it to only 2 items per feed
For each item in a feed, do something
Translate an English feed to French
Part II: Reading pipes in PHP
$url = 'http://pipes.yahoo.com/pipes/pipe.run?'
. '_id=vI7LxsJe3BGRHaLP6UjTQA&_render=php';
function fetchURL($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_POST, 0 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
return curl_exec($ch);
}
$url = 'http://pipes.yahoo.com/pipes/pipe.run?'
. '_id=vI7LxsJe3BGRHaLP6UjTQA&_render=php';
function fetchURL($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_POST, 0 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
return curl_exec($ch);
}
$url = 'http://pipes.yahoo.com/pipes/pipe.run?'
. '_id=vI7LxsJe3BGRHaLP6UjTQA&_render=php';
function fetchURL($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_POST, 0 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
return curl_exec($ch);
}
$data = unserialize(fetchURL($url));
Part III: YQL
<?php
$url = "http://query.yahooapis.com/v1/public/yql?q=";
$q = "select * from flickr.photos.search(100) where text='webdu'";
$fmt = "xml";
$x = simplexml_load_file($url.urlencode($q)."&format=$fmt");
foreach($x->attributes('http://www.yahooapis.com/v1/base.rng') as $k=>$v) {
$$k=(string)$v;
}
echo <<<EOB
$count photos fetched from
{$x->diagnostics->url} in
{$x->diagnostics->url['execution-time']} seconds<br>
EOB;
$flickr = "http://static.flickr.com/";
foreach($x->results->photo as $p) {
echo "<img src=\"$flickr{$p['server']}/{$p['id']}_{$p['secret']}_s.jpg\"/>\n";
}
?>
<?php
$yql = "http://query.yahooapis.com/v1/public/yql?q=";
$q = "use 'http://airports.pidgets.com/v1/tables.xml' as airports;".
"select * from airports(5) where near='Sydney' and direct_flights_min=20";
$x = simplexml_load_file($yql.urlencode($q).'&format=xml');
echo "<b>URLs accessed:</b><br>\n";
foreach($x->diagnostics->url as $u) {
echo "<a href=\"$u\">$u</a><br>\n";
}
echo "<br>";
foreach($x->results->airport as $a) {
echo <<<EOB
{$a->code} <a href="{$a->url}">{$a->name}</a> {$a->dist}km<br>
EOB;
}
?>
Made with Eric A Meyer's S5