Top Banner
Remixing web data for your hacks the easy way YQL – the can opener of the web
76

Open Hack London - Introduction to YQL

Sep 12, 2014

Download

Education

An introduction to YQL for hackers at the open hack day in London, talking about code demos at http://isithackday.com/hacks/ohd-london/
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Open Hack London - Introduction to YQL

Remixing web data for your hacks the easy way

YQL – the can opener of the web

Page 2: Open Hack London - Introduction to YQL

Hacking together systems in 24 hours is a lot of fun.

Page 3: Open Hack London - Introduction to YQL

But you want to spend that time thinking about the interface.

Page 4: Open Hack London - Introduction to YQL

And not how you get to the right data in the right format.

Page 5: Open Hack London - Introduction to YQL

The web is full of juicy and long lasting data.

h"p://www.flickr.com/photos/clspeace/162336973/

Page 6: Open Hack London - Introduction to YQL

And there is a lot of it around.

h"p://www.flickr.com/photos/tudor/2981410947/

Page 7: Open Hack London - Introduction to YQL

However, our attempts to get to it can be clumsy.

h"p://www.flickr.com/photos/lumachrome/2140368742/

Page 8: Open Hack London - Introduction to YQL

What we need is an easy way to get to that data.

h"p://www.flickr.com/photos/carey@lden/115435226/

Page 9: Open Hack London - Introduction to YQL

We had a way to do that for quite a while now.

Page 10: Open Hack London - Introduction to YQL

http://pipes.yahoo.com/

Page 11: Open Hack London - Introduction to YQL

Pipes, however is high end technology…

h"p://www.flickr.com/photos/axio/2346342672/

Page 12: Open Hack London - Introduction to YQL

We’re developers, not interface users.

h"p://www.flickr.com/photos/codepo8/2278641937/

Page 13: Open Hack London - Introduction to YQL

So for a long time people asked Yahoo for a command line version of pipes.

Can we have one?

Page 14: Open Hack London - Introduction to YQL

Yes, we can!

Page 15: Open Hack London - Introduction to YQL

The Yahoo Query Language, or short YQL is a unified interface language to the web.

http://developer.yahoo.com/yql/

Page 16: Open Hack London - Introduction to YQL

Using YQL, accessing the web and its services becomes as easy as SQL:

select {what} from {service} where {condition}

Page 17: Open Hack London - Introduction to YQL

Say you want kittens in your hack (who doesn’t?)

select * from flickr.photos.search where text="kitten"

Page 18: Open Hack London - Introduction to YQL

Say you want kittens in your hack (who doesn’t?)

Page 19: Open Hack London - Introduction to YQL

Say you only want 5 kittens

select * from flickr.photos.search where text="kitten" limit 5

Page 20: Open Hack London - Introduction to YQL

Say you only want 5 kittens

Page 21: Open Hack London - Introduction to YQL

Nice, but where can you get this?

Page 22: Open Hack London - Introduction to YQL

YQL is a REST API in itself, and it has two endpoints.

Page 23: Open Hack London - Introduction to YQL

The public endpoint does not need any authentication.

http://query.yahooapis.com/v1/public/yql?q={query}&format={format}

Page 24: Open Hack London - Introduction to YQL

The private endpoint needs oauth authentication.

http://query.yahooapis.com/v1/yql?q={query}&format={format}

h"p://developer.yahoo.com/yql/guide/authoriza@on‐access.html

Page 25: Open Hack London - Introduction to YQL

Output formats are XML or JSON. JSON also allows for a callback parameter to use the output directly as JSON-P.

Page 26: Open Hack London - Introduction to YQL

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from flickr.photos.search%20where%20text=%22kitten%22limit%205&format=json&callback=meow

Page 27: Open Hack London - Introduction to YQL
Page 28: Open Hack London - Introduction to YQL

You can mix and match several web services using the in() command.

Page 29: Open Hack London - Introduction to YQL

Guess what this does:

select * from flickr.photos.info where photo_id in (select id from flickr.photos.search where woe_id in (select woeid from geo.places where text='london,uk') and license=4)

Page 30: Open Hack London - Introduction to YQL

Find London, UK, without a doubt.select * from flickr.photos.info where photo_id in (select id from flickr.photos.search where woe_id in (select woeid from geo.places where text='london,uk') and license=4)

Page 31: Open Hack London - Introduction to YQL

Find Photos of London, UK

select * from flickr.photos.info where photo_id in (select id from flickr.photos.search where woe_id in (select woeid from geo.places where text='london,uk') and license=4)

Page 32: Open Hack London - Introduction to YQL

Find Photos of London, UK with a “By” CC license select * from flickr.photos.info where photo_id in (select id from flickr.photos.search where woe_id in (select woeid from geo.places where text='london,uk') and license=4)

Page 33: Open Hack London - Introduction to YQL

Give me everything you know about these photos.select * from flickr.photos.info where photo_id in (select id from flickr.photos.search where woe_id in (select woeid from geo.places where text='london,uk') and license=4)

Page 34: Open Hack London - Introduction to YQL

Using a command like this and some out-of-the-box UI elements like Yahoo Maps and the YUI carousel, you can build something *very* quickly.

Page 36: Open Hack London - Introduction to YQL

Instead of selecting all the information you can also limit the results:

select name,url from upcoming.venue where metro_id in (select id from upcoming.metro where search_text="stokey")

Page 37: Open Hack London - Introduction to YQL

select name,url from upcoming.venue where metro_id in (select id from upcoming.metro where search_text="stokey")

Page 38: Open Hack London - Introduction to YQL

The diagnostics part of the returned data shows you what happened and how long it took

Page 39: Open Hack London - Introduction to YQL

Here’s what Yahoo offers you in this format:

flickr.photos.exifflickr.photos.infoflickr.photos.interes0ngnessflickr.photos.recentflickr.photos.searchflickr.photos.sizesflickr.placesflickr.places.infogeo.placesgeo.places.ancestorsgeo.places.belongtosgeo.places.childrengeo.places.neighborsgeo.places.parentgeo.places.siblingsgeo.placetypesgnip.ac0vity

local.searchmusic.ar0st.idmusic.ar0st.popularmusic.ar0st.searchmusic.ar0st.similarmusic.release.ar0stmusic.release.idmusic.release.popularmusic.release.searchmusic.track.idmusic.track.popularmusic.track.searchmusic.video.categorymusic.video.idmusic.video.popularmusic.video.searchmusic.video.similar

mybloglog.community.findmybloglog.membermybloglog.member.contactsmybloglog.member.newwithcontactsmybloglog.member.newwithmemybloglog.members.findmybloglog.stats.findupcoming.categoryupcoming.countryupcoming.eventsupcoming.events.bes0nplaceupcoming.groupsupcoming.metroupcoming.stateupcoming.userupcoming.venue

Page 40: Open Hack London - Introduction to YQL

Here’s what Yahoo offers you in this format:

search.imagessearch.newssearch.siteexplorer.inlinkssearch.siteexplorer.pagessearch.spellingsearch.suggestsearch.termextractsearch.websocial.connec0onssocial.contactssocial.presencesocial.profilesocial.updatesweather.forecastyahoo.iden0tyyap.setsmallview

search.imagessearch.newssearch.siteexplorer.inlinkssearch.siteexplorer.pagessearch.spellingsearch.suggestsearch.termextractsearch.websocial.connec0onssocial.contactssocial.presencesocial.profilesocial.updatesweather.forecastyahoo.iden0tyyap.setsmallview

search.imagessearch.newssearch.siteexplorer.inlinkssearch.siteexplorer.pagessearch.spellingsearch.suggestsearch.termextractsearch.websocial.connec0onssocial.contactssocial.presencesocial.profilesocial.updatesweather.forecastyahoo.iden0tyyap.setsmallview

Page 41: Open Hack London - Introduction to YQL

You want even more?

http://www.flickr.com/photos/verylastexcitingmoment/3123597774/

Page 42: Open Hack London - Introduction to YQL

Alright, how about this?

atomcsvfeedhtml

jsonmicroformatsrssxml

Page 43: Open Hack London - Introduction to YQL

Telegraph’s headlines anyone?select * from html where url='http://www.telegraph.co.uk/' and xpath='//h3/a'

Page 44: Open Hack London - Introduction to YQL

Telegraph’s headlines anyone?

Page 45: Open Hack London - Introduction to YQL

You can dynamically create YQL queries to collate several sources…

Page 46: Open Hack London - Introduction to YQL

Then use cURL to pull them off the web with one single http request!

Page 47: Open Hack London - Introduction to YQL

YQL caches and compresses the results for you.

Pretty easy, isn’t it?

Page 48: Open Hack London - Introduction to YQL

Here’s another fun part:Anyone can be part of the YQL interface.

Page 49: Open Hack London - Introduction to YQL

All we need the data provider to do is to create a schema that explains their data structure.

http://developer.yahoo.com/yql/guide/yql-opentables-chapter.html

Page 50: Open Hack London - Introduction to YQL

And people do…amazonbitlydeliciousdopplretsyfriendfeedgithubGreaderguardianimdbiploca0onlas>mnestoriane>lix

nmmnytopensocialsearchshoppingsocialtwi?erupdate.groovyweatherwesabewhitepagesyahooyelpzillow

http://github.com/spullara/yql-tables/tree/master

Page 51: Open Hack London - Introduction to YQL

For example the national maritime museum:

select * from nmm.archive.search where searchterm=‘horatio nelson'

Page 52: Open Hack London - Introduction to YQL

select * from nmm.archive.search where searchterm=‘horatio nelson'

Page 53: Open Hack London - Introduction to YQL

That’s pretty cool – allowing anyone to be part of this interface.

Page 54: Open Hack London - Introduction to YQL

The only shame is that you can’t do all the things in YQL that you can do in Pipes – for example string manipulation.

Page 55: Open Hack London - Introduction to YQL

We wondered how to make this possible.

One thing we didn’t want to sacrifice is the simplicity of the language itself.

Page 56: Open Hack London - Introduction to YQL

So instead of inventing an own language, we decided to piggy-back on one you already know.

Page 57: Open Hack London - Introduction to YQL

YQL execute allows you to embed JavaScript in the open table schema that runs on the YQL server and converts the data for you.

http://developer.yahoo.com/yql/guide/yql-execute-chapter.html

Page 58: Open Hack London - Introduction to YQL

For example you can augment an existing service to do something different.

Page 59: Open Hack London - Introduction to YQL

The following example adds a rank to search results.

http://www.yqlblog.net/samples/searchrank.xml

Page 60: Open Hack London - Introduction to YQL
Page 61: Open Hack London - Introduction to YQL
Page 62: Open Hack London - Introduction to YQL

Stored as XML this can be used in a YQL query:

use 'http://yqlblog.net/samples/searchrank.xml' as searchrank; select * from searchrank where query='pizza' and dispurl like '%pizzahut%'

Page 63: Open Hack London - Introduction to YQL
Page 64: Open Hack London - Introduction to YQL

Anyways, the *easiest* way to start with YQL is to use the console.

http://developer.yahoo.com/yql/console/

Page 65: Open Hack London - Introduction to YQL
Page 66: Open Hack London - Introduction to YQL
Page 67: Open Hack London - Introduction to YQL
Page 68: Open Hack London - Introduction to YQL
Page 69: Open Hack London - Introduction to YQL
Page 70: Open Hack London - Introduction to YQL
Page 71: Open Hack London - Introduction to YQL
Page 72: Open Hack London - Introduction to YQL
Page 73: Open Hack London - Introduction to YQL
Page 74: Open Hack London - Introduction to YQL

Of course, you can also spend half the hack day reading API docs

Page 75: Open Hack London - Introduction to YQL

Check out some code examples on.

http://isithackday.com/hacks/ohd-london

Page 76: Open Hack London - Introduction to YQL

THANKS!Chris Heilmannhttp://twitter.com/codepo8