svn: /web/presentations/trunk/slides/intro/ api_yql1.xml api_yql2.xml tapachula_ref.xml yql.php

From: Date: Fri, 27 May 2011 20:26:56 +0000
Subject: svn: /web/presentations/trunk/slides/intro/ api_yql1.xml api_yql2.xml tapachula_ref.xml yql.php
Groups: php.pres 
Request: Send a blank email to pres+get-1719@lists.php.net to get a copy of this message
rasmus Fri, 27 May 2011 20:26:56 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=311512 Log: 2 new YQL slides Changed paths: A web/presentations/trunk/slides/intro/api_yql1.xml A web/presentations/trunk/slides/intro/api_yql2.xml U web/presentations/trunk/slides/intro/tapachula_ref.xml A web/presentations/trunk/slides/intro/yql.php Added: web/presentations/trunk/slides/intro/api_yql1.xml =================================================================== --- web/presentations/trunk/slides/intro/api_yql1.xml (rev 0) +++ web/presentations/trunk/slides/intro/api_yql1.xml 2011-05-27 20:26:56 UTC (rev 311512) @@ -0,0 +1,27 @@ +<slide title="Yahoo Query Language - YQL"> + +<break lines="1"/> +<blurb fontsize="4em">YQL: SELECT * from WEB</blurb> +<example result="1" hide="1" fontsize="1.4em"><![CDATA[<?php +if(!empty($_POST['name'])) $name = htmlspecialchars($_POST['name'], ENT_QUOTES, 'UTF-8'); +else $name='Rasmus'; +?> +<form action="<?php echo htmlspecialchars($PHP_SELF)?>" method="POST"> +SELECT * FROM firstnames.lookup WHERE name = "<input autocomplete="off" style="font-size: 24px;" type=text name=name value="<?php echo $name?>" size=10>" +</form> +<?php +include 'presentations/slides/intro/yql.php'; +$x = yql('SELECT * FROM firstnames.lookup WHERE name="'.$name.'"'); +$name = $x->results->restnames->nameinfo; +echo "Name: {$name->name}<br />\n"; +echo "Gender: {$name->gender}<br />\n"; +echo "Countries: "; +$countries=''; +foreach($name->countries->country as $c) $countries.=((string)$c).", "; +$countries = rtrim($countries,", "); +echo $countries; +?> +]]></example> + + +</slide> Added: web/presentations/trunk/slides/intro/api_yql2.xml =================================================================== --- web/presentations/trunk/slides/intro/api_yql2.xml (rev 0) +++ web/presentations/trunk/slides/intro/api_yql2.xml 2011-05-27 20:26:56 UTC (rev 311512) @@ -0,0 +1,26 @@ +<slide title="Yahoo Query Language - YQL"> + +<break lines="1"/> + +<example result="1" hide="1" fontsize="1.4em"><![CDATA[<?php +include 'presentations/slides/intro/yql.php'; +if(!empty($_POST['loc'])) $loc = htmlspecialchars($_POST['loc'], ENT_QUOTES, 'UTF-8'); +else $loc=':-:location:-:'; +?> +<form action="<?php echo htmlspecialchars($PHP_SELF)?>" method="POST"> +select * from wunderground.forecast where location = "<input autocomplete="off" style="font-size: 24px;" type=text name=loc value="<?php echo $loc?>" size=14>" +</form> +<?php +$x = yql("select * from wunderground.forecast where location='$loc'"); +$f = $x->results->forecast->simpleforecast; +echo "<br />\n"; +foreach($f->forecastday as $w) { + echo '<img style="float:left;" src="'.((string)$w->icons->icon_set[0]->icon_url).'"/>'; + echo $w->date->weekday.' '.$w->date->monthname.' '.$w->date->day." &nbsp; &nbsp; "; + echo $w->conditions."<br />\n"; + echo "low: {$w->low->celsius}°C ({$w->low->fahrenheit}F) high: {$w->high->celsius}°C ({$w->high->fahrenheit}F)"; + echo "<br />\n<br />\n"; +} +?>]]></example> + +</slide> Modified: web/presentations/trunk/slides/intro/tapachula_ref.xml =================================================================== --- web/presentations/trunk/slides/intro/tapachula_ref.xml 2011-05-27 19:50:06 UTC (rev 311511) +++ web/presentations/trunk/slides/intro/tapachula_ref.xml 2011-05-27 20:26:56 UTC (rev 311512) @@ -5,6 +5,8 @@ <link fontsize="2em" marginleft="2em" leader="Yahoo Maps API: " href="http://developer.yahoo.com/maps"/> <link fontsize="2em" marginleft="2em" leader="Twitter API: " href="http://dev.twitter.com/doc"/> <link fontsize="2em" marginleft="2em" leader="Google Geocoding API: " href="http://code.google.com/apis/maps/documentation/geocoding"/> +<link leader="YQL: " fontsize="2em" marginleft="2em" href="http://developer.yahoo.com/yql"/> + <break lines="2"/> <blurb fontsize="6em" align="center">Preguntas?</blurb> </slide> Added: web/presentations/trunk/slides/intro/yql.php =================================================================== --- web/presentations/trunk/slides/intro/yql.php (rev 0) +++ web/presentations/trunk/slides/intro/yql.php 2011-05-27 20:26:56 UTC (rev 311512) @@ -0,0 +1,23 @@ +<?php +include 'secrets.inc'; +define('MINSZ',10); +function cache($url) { + $tmp = '/tmp/'.md5($url); + if(file_exists($tmp)) $st = stat($tmp); + if(!$st || $st && ($st['size']<MINSZ || $st['mtime']<(time()-7200))) { + if($st && $st['size']>=MINSZ) touch($tmp); // Keep re-using entry + $stream = fopen($url,'r'); // until new is ready + $tmpf = tempnam('/tmp','YWS'); + file_put_contents($tmpf, $stream); + fclose($stream); + rename($tmpf, $tmp); + } + return $tmp; +} + +function yql($q, $fmt='xml') { + $yql = "http://query.yahooapis.com/v1/public/yql?q="; + $env = 'store://datatables.org/alltableswithkeys'; + $x = simplexml_load_file(cache($yql.urlencode($q)."&format=$fmt&env=".urlencode($env))); + return $x; +} Property changes on: web/presentations/trunk/slides/intro/yql.php ___________________________________________________________________ Added: svn:keywords + Id Rev Revision Added: svn:eol-style + native

« previous php.pres (#1719) next »