Permalink
Browse files

sample tables from the blog post

  • Loading branch information...
1 parent 7b4d74a commit 3d8e3522edaa0f0334d800613bf755e9620fedc1 Samuel Pullara committed May 3, 2009
View
30 data/data.html.cssselect.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
+ <meta>
+ <sampleQuery>select * from {table} where url="www.yahoo.com" and css="#news a"</sampleQuery>
+ </meta>
+ <bindings>
+ <select itemPath="" produces="XML">
+ <urls>
+ <url></url>
+ </urls>
+ <inputs>
+ <key id="url" type="xs:string" paramType="variable" required="true" />
+ <key id="css" type="xs:string" paramType="variable" />
+ </inputs>
+ <execute><![CDATA[
+ //include css to xpath convert function
+ y.include("http://james.padolsey.com/scripts/javascript/css2xpath.js");
+ var query = null;
+ if (css) {
+ var xpath = CSS2XPATH(css);
+ y.log("xpath "+xpath);
+ query = y.query("select * from html where url=@url and xpath=\""+xpath+"\"",{url:url});
+ } else {
+ query = y.query("select * from html where url=@url",{url:url});
+ }
+ response.object = query.results;
+ ]]></execute>
+ </select>
+ </bindings>
+</table>
View
25 flickr/flickr.auth.frob.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd" https="true">
+ <meta>
+ <sampleQuery> select * from {table}</sampleQuery>
+ </meta>
+ <bindings>
+ <select itemPath="rsp" produces="XML">
+ <urls>
+ <url>http://api.flickr.com/services/rest/</url>
+ </urls>
+ <inputs>
+ <key id='method' type='xs:string' paramType='variable' const="true" default="flickr.auth.getFrob" />
+ <key id='api_key' type='xs:string' paramType='variable' required="true" />
+ <key id='secret' type='xs:string' paramType='variable' required="true" />
+ </inputs>
+ <execute><![CDATA[
+// Include the flickr signing library
+y.include("http://www.yqlblog.net/samples/flickr.js");
+// GET the flickr result using a signed url
+var fs = new flickrSigner(api_key,secret);
+response.object = y.rest(fs.createUrl({method:method, format:""})).get().response();
+ ]]></execute>
+ </select>
+ </bindings>
+</table>
View
147 imdb/imdb.celeb.birthdays.xml
@@ -0,0 +1,147 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
+ <meta>
+ <sampleQuery> select * from {table}</sampleQuery>
+ </meta>
+ <bindings>
+ <select itemPath="birthdays.person" produces="XML">
+ <urls>
+ <url></url>
+ </urls>
+<!-- since we can't match paging to the underlying BOSS paging model precisely, we'll just claim we can do fixed start (0) with variable
+ number of results -->
+ <paging model="offset">
+ <pagesize id="count" max="300" />
+ <total default="10" />
+ </paging>
+ <inputs>
+ <key id='date' type='xs:string' paramType='variable' />
+ </inputs>
+ <execute><![CDATA[
+
+//object to query imdb to extract bio info for a person
+var celebInfo = function(name,url) {
+ this.url = url;
+ this.name = name;
+ var querystring = "select * from html where url = '"+url+"' and xpath=\"//div[@id='tn15']\"";
+ this.query = y.query(querystring);
+}
+
+//actually extract the info and return an xml object
+celebInfo.prototype.getData=function() {
+ default xml namespace ='';
+ var d = this.query.results;
+ var img = d..div.(@["id"]=="tn15lhs").div.a.img;
+ var content = d..div.(@['id'] =="tn15content");
+ var bio = "";
+ //this is pretty hacky
+ for each (var node in content.p) {
+ if (node.text().toString().trim().length>100) {
+ bio = node.*;
+ break;
+ }
+ }
+ var anchors = content.a;
+ var bornInYear = null;
+ var bornWhere = null;
+ var diedInYear = null;
+ var onThisDay = [];
+ //TODO see if there is a wildcard way of pulling these out using e4x/xpath
+ for each (var a in anchors) {
+ var href = a.@['href'].toString();
+ if (href.indexOf("/BornInYear")==0) {
+ bornInYear = a.toString().trim();
+ continue;
+ }
+ if (href.indexOf("/DiedInYear")==0) {
+ diedInYear = a.toString().trim();
+ continue;
+ }
+ if (href.indexOf("/BornWhere")==0) {
+ bornWhere = a.toString().trim();
+ continue;
+ }
+ if (href.indexOf("/OnThisDay")==0) {
+ onThisDay.push(a.text().toString().trim());
+ continue;
+ }
+ }
+ var bornDayMonth=null;
+ var diedDayMonth=null;
+ if (onThisDay.length>0) {
+ bornDayMonth = onThisDay[0].replace(/^\s*(\d{1,2})[\s]+(\w+)\s*/,'$1 $2'); //tidy up whitespace around text
+ if (diedInYear && onThisDay.length>1) {
+ diedDayMonth= onThisDay[1].replace(/^\s*(\d{1,2})[\s]+(\w+)\s*/,'$1 $2'); //tidy up whitespace around text
+ }
+ }
+ var url = this.url;
+ var name = this.name;
+ var bornTime = null;
+ if (bornDayMonth) {
+ var daymonth = bornDayMonth.split(" ");
+ bornTime=new Date(bornInYear,Date.getMonthFromString(daymonth[1]),parseInt(daymonth[0])).getTime()/1000;
+ }
+ var diedTime = null;
+ if (diedDayMonth) {
+ var daymonth = diedDayMonth.split(" ");
+ diedTime=new Date(diedInYear,Date.getMonthFromString(daymonth[1]),parseInt(daymonth[0])).getTime()/1000;
+ }
+ var person = <person url={url}><name>{name}</name>{img}<born utime={bornTime}>{bornDayMonth} {bornInYear}</born></person>;
+ if (diedTime) person.person+=<died utime={diedTime}>{diedDayMonth} {diedInYear}</died>;
+ if (bio) person.person+=<bio>{bio}</bio>;
+ return person;
+}
+
+//general useful routines
+String.prototype.trim =function() {
+ return this.replace(/^[\s]*/,'').replace(/[\s]*$/,'');
+}
+Date.getMonthFromString = function(month) {
+ return {'January':0, 'February':1, 'March':2, 'April':3, 'May':4, 'June':5, 'July':6, 'August':7, 'September':8, 'October':9, 'November':10, 'December':11}[month];
+}
+Date.prototype.getMonthName = function() {
+ return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][this.getMonth()];
+}
+
+//the main object that uses boss to get the list (also gets peoples "death" days too)
+celebSearch = function(when,start,count) {
+ //search yahoo/boss using the current day and month only on bio pages on imdb
+ var bornDayMonth = when.getDate()+" "+when.getMonthName();
+ var ud = Math.round(when.getTime()/1000);
+ var search = 'site:www.imdb.com "Date of birth" "'+bornDayMonth+'" title:biography'
+ var query = "select * from search.web("+start+","+count+") where query='"+search+"'";
+ var celebs = y.query(query).results;
+
+ //go through each result and start to get the persons name and their imdb info page out
+ var results = [];
+ default xml namespace ='http://www.inktomi.com/'; //make sure our e4x is in the right namespace. IMPORTANT
+ for each (var celeb in celebs.result) {
+ //discard any hits on the date of death that also match in our yahoo search
+ //(this is going to hurt our paging)
+ if (celeb["abstract"].toString().indexOf("<b>Date of Birth</b>. <b>"+bornDayMonth)<0) continue;
+ var j = celeb.title.toString().indexOf("-"); //use text up to "dash" from title for name
+ var name = celeb.title.toString().substring(0,j).trim();
+ //start parsing these entries by pulling from imdb directly
+ results.push(new celebInfo(name,celeb.url));
+ }
+
+ //loop through each imdb fetch result, and create the result object
+ default xml namespace = '';
+ var data = <birthdays utime={ud} date={when} />;
+ for each (var celeb in results) {
+ data.birthdays+=celeb.getData();
+ }
+ return data;
+}
+
+//run it for today if no date was provided
+var when = new Date();
+if (date && date.length>0) {
+ when = new Date(date); //TODO needs a well formed date including year
+}
+response.object = new celebSearch(when,0,count);
+
+ ]]></execute>
+ </select>
+ </bindings>
+</table>
View
45 netflix/netflix.catalog.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd" https="true">
+ <meta>
+ <author>Paul Donnelly</author>
+ <documentationURL>http://developer.netflix.com/docs/REST_API_Reference#0_52696</documentationURL>
+ </meta>
+ <bindings>
+ <select itemPath="" produces="XML" >
+ <urls>
+ <url env="all">http://api.netflix.com/catalog/titles/</url>
+ </urls>
+ <paging model="offset">
+ <start id="start_index" default="0" />
+ <pagesize id="max_results" max="100" />
+ <total default="10" />
+ </paging>
+ <inputs>
+ <key id="term" type="xs:string" paramType="query" required="true" />
+ <key id="ck" type="xs:string" paramType="variable" required="true" />
+ <key id="cks" type="xs:string" paramType="variable" required="true" />
+ </inputs>
+ <execute><![CDATA[
+// Include the OAuth libraries from oauth.net
+y.include("http://oauth.googlecode.com/svn/code/javascript/oauth.js");
+y.include("http://oauth.googlecode.com/svn/code/javascript/sha1.js");
+
+// Collect all the parameters
+var encodedurl = request.url;
+var accessor = { consumerSecret: cks, tokenSecret: ""};
+var message = { action: encodedurl, method: "GET", parameters: [["oauth_consumer_key",ck],["oauth_version","1.0"]]};
+OAuth.setTimestampAndNonce(message);
+
+// Sign the request
+OAuth.SignatureMethod.sign(message, accessor);
+
+try {
+ // get the content from service along with the OAuth header, and return the result back out
+ response.object = request.contentType('application/xml').header("Authorization", OAuth.getAuthorizationHeader("netflix.com", message.parameters)).get().response;
+} catch(err) {
+ response.object = {'result':'failure', 'error': err};
+}
+ ]]></execute>
+ </select>
+ </bindings>
+</table>
View
42 search/search.imageweb.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
+ <meta>
+ <author>Nagesh Susarla</author>
+ <documentationURL>See search.web and search.images for more details</documentationURL>
+ </meta>
+ <bindings>
+ <select itemPath="results.result" produces="XML">
+ <urls>
+ <url></url>
+ </urls>
+ <inputs>
+ <key id="query" type="xs:string" paramType="query" required="true"/>
+ </inputs>
+
+ <execute><![CDATA[
+
+ var qs = query;
+
+ var search = y.query('select * from search.web(50) where query=@query', {query: qs}).results;
+ var images = [];
+ default xml namespace='http://www.inktomi.com/';
+ for each (var result in search.result) {
+ images.push(y.query('select * from search.images(1) where query=@query and url=@url', {url:result.url, query:qs}));
+ }
+
+ var i = 0;
+
+ for each (var result in search.result) {
+ var image = images[i].results.result;
+ if (image) {
+ result.image = <image>{image}</image>;
+ }
+ i++;
+ }
+
+ response.object = search;
+ ]]>
+ </execute>
+ </select>
+ </bindings>
+</table>
View
35 search/search.rank.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
+ <meta>
+ <author>Nagesh Susarla</author>
+ <documentationURL>My Search Rank</documentationURL>
+ </meta>
+ <bindings>
+ <select itemPath="results.result" produces="XML">
+ <urls>
+ <url></url>
+ </urls>
+ <paging model="offset">
+ <start id="start" default="0" />
+ <pagesize id="count" max="50" />
+ <total default="10"/>
+ </paging>
+ <inputs>
+ <key id="query" type="xs:string" paramType="variable" required="true"/>
+ </inputs>
+ <execute><![CDATA[
+ var theQuery = 'select * from search.web(' + start + ',' + count + ') where query=@query '
+ var search = y.query(theQuery, {query:query}).results;
+ var rank = 0 + start;
+ //y.log("initing rank");
+ default xml namespace = 'http://www.inktomi.com/';
+ for each (var result in search.result) {
+ rank++;
+ //y.log("rank for " + rank);
+ result.rank += <rank>{rank}</rank>;
+ }
+ response.object = search;
+ ]]></execute>
+ </select>
+ </bindings>
+</table>
View
71 social/social.friendapps.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd" securityLevel="user">
+ <meta>
+ <sampleQuery> select * from {table}</sampleQuery>
+ </meta>
+ <bindings>
+ <select itemPath="root.install.app" produces="XML">
+ <urls>
+ <url></url>
+ </urls>
+ <inputs>
+ <key id='friendguid' type='xs:string' paramType='variable' />
+ </inputs>
+ <execute><![CDATA[
+ function createInstallElement(update,type) {
+ var bits = update.itemurl.toString().split("/");
+ var appid = bits[bits.length-2].substring(1);//get the appid from the install url
+ var title = update.title.toString();
+ default xml namespace = '';
+ var el = <app who={type} id={appid}>{title}</app>;
+ default xml namespace = 'http:://social.yahooapis.com/v1/updates/schema.rng';
+ return el;
+ }
+
+ default xml namespace = '';
+ var root = <install/>;
+
+ //get my friends installs from updates
+ var friendapp_installs = null;
+ if (friendguid) {
+ //only do deltas to this friend
+ friendapp_installs = y.query('select title, itemtxt, itemurl from social.updates(1000) where guid=@guid and type="appInstall" | unique(field="itemtxt")',{guid:friendguid});
+ } else {
+ //all friends
+ friendapp_installs = y.query('select title, itemtxt, itemurl from social.updates(1000) where guid in (select guid from social.connections(0) where owner_guid=me) and type="appInstall" | unique(field="itemtxt")');
+ }
+ //get my installs from updates
+ var myapp_installs = y.query('select title, itemtxt, itemurl from social.updates(1000) where guid=me and type="appInstall" | unique(field="itemtxt")');
+ //we're going to keep a collection for each variant of the diff between my installs and my friend(s)
+ var myapp_installs = myapp_installs.results;
+ var friendapp_installs = friendapp_installs.results;
+ default xml namespace = 'http:://social.yahooapis.com/v1/updates/schema.rng';
+ for each (var myupdate in myapp_installs.update) {
+ y.log("myupdate "+myupdate.localName());
+ //use e4x to search for matching node in friendapp with the same itemtxt (appid)
+ var matching = friendapp_installs.update.(itemtxt==myupdate.itemtxt.toString());
+ if (matching.length()>0) {
+ //found, we both have it
+ root.install+=createInstallElement(myupdate,"shared");
+ //y.log("Found "+myupdate.title+" in both");
+ myupdate.@matched = true;
+ matching.@matched = true;
+ } else {
+ //not in my friends apps, so add it to me only list
+ //y.log("Found "+myupdate.title+" in mine only");
+ root.install+=createInstallElement(myupdate,"me");
+ myupdate.@matched = true;
+ }
+ }
+ //anything left in the friends app list that doesnt have a "match" attribute is not installed by me
+ for each (var friendupdate in friendapp_installs.update.(@matched!=true)) {
+ //y.log("Found "+friendupdate.title+" in my friends only");
+ root.install+=createInstallElement(friendupdate,"friend");
+ }
+ //return the three sets of results
+ default xml namespace = '';
+ response.object = <root>{root}</root>;
+ ]]></execute>
+ </select>
+ </bindings>
+</table>

0 comments on commit 3d8e352

Please sign in to comment.