Executing your javascript in the cloud, yes! YQL rules!

noviembre 18th, 2010 § 3 comments § permalink

First of all, I'm  not going to start talking about nodejs, that's another post I have pending. This time I'm talking again about YQL, yes, that awesome tool that will save you a lot of time.

Most of you should be familiar with it, do you remember 'select * from internet' ? You could pick data from different sources, mashup it, mix, filter, etc. But also create new content sources, this makes you the ability to turn ANY (yes in capital case) digital resource (an api, html, csv, what ever!!) into a YQL content source.

But, today I want to talk about another super cool feature YQL has, is the ability of executing javascript in the tables that you create. This is perfectly documented in YDN , it's call the 'execute' block, it let's you transform the data, doing really granular parsing and filtering, basically, transforming the data in any way your mind can image.

So, with this tools in my hands, a dirty idea started to grew in my head: ... can I use YQL to execute javascript in a fancy way?

And after some lines of table definition, 5 minutes :P , a new table was born, the 'execute' table, it's included in the community open tables, so once you are in the console, click on 'Show Community Tables' and you will be ready to use it.

How can you execute your javascript code using this table? Easy, if you use the query builder, you could see the following fields available for the table:

  • code: With this parameter you directly write inline the code to be executed.
  • file: You specify a url or a YQL internal storage key where your code resides.

You can use both parameters as well, first will be executed the code in the 'file' parameter and after that the 'code' one.

How queries look like:

CODE:
  1.  
  2. select * from execute where code="response.object=<hello><world/></hello>;"
  3.  
  4. select * from execute where file="http://myserver/myfile.js"
  5.  

And now why use this?

  • I want to replace html5 Web Workers, no way, I'm joking, but is another option to relay the execution of the javascript not in the client, maybe could be useful for really old phones.
  • YQL prototyping. This is really helpful for people that use extremely YQL, and deal with the infamous and loved 'execute' block. Will reduce considerably your development time. In conjunction with Sam's Pullara yql storage editor, is the definitive tool to work with YQL.

Hope you liked it, happy hacking!!

Mobile web applications: Fast development with Yahoo! Blueprint, YQL and Django.

mayo 4th, 2010 § 7 comments § permalink

Today I´m going to show you how to develop a nice web application for mobile devices mixing 3 of my favourites technologies: Yahoo! Blueprint, YQL and Django.

Let me present those technologies, just in case you still don´t know:

  • Yahoo! Blueprint: is the technology we use at yahoo to rock the mobile world! Create awesome services and don´t worry about the inconveniences of a environment with lots of terminals, just write your application and we at Yahoo! will take care of everything else.
  • YQL: is the abbreviation for Yahoo! Query Language. It´s a great and powerful technology that will help you ´sqlize´web services. As their leitmotiv says "SELECT * FROM INTERNET" start using YQL, select, filter, combine different data sources with just a simple query.
  • Django: is a famous web development framework written on Python. Django will help you create easy and robust web applications using the model/template/view paradigm.

Our web application

Each time I move to a new city or I´m looking for a new home, I spend lots of hours surfing the web trying to find the perfect ´sweet home´. I´d like to search for the precious home even if I´m not in front of my computer.

Today we are going to help those flat seekers, we are going to build a mobile property finder using the Nestoria web services. Check out the Nestoria api and you will understand our YQL queries.

We will retrieve the information from the Nestoria web service using YQL and will output blueprint using the Django framework,a nice application stack to develop awesome mobile applications.

What will do our mobile web application? Easy, we will present the user a simple form asking for a location where to search, a maximun price (per week) and also the minimun number of bedrooms. Once the user enter this information we will present a list with all results found, then each item from that list will point to the original web page that contains the information for each flat. Simple, but is a nice first step, if you like you can add more information to the search form or to the presentation layer.

Getting the data with YQL

As you may know, YQL is a rocking idea from Y!, it´s a way of sqlize web services, and of course it´s open. That means we can create new tables, share them, reuse other people tables etc.

Visit http://datatables.org/, and get an idea on how many people are right now building tables for lots and lots of web services. Come on! Check the tables, experiment search parameters and data combinations in the YQL console: http://developer.yahoo.com/yql/console/

For our particular case, there is a Nestoria open table so we can use this to extract the data. Here is the table code, check it, take a look to the parameters, you can perform the same actions as using the web service.

Diving into the Yahoo! world we can find another good hint, the YOS people have created lots of libraries in lots of languages to interact with all Yahoo open services, and of courses YQL is one of those services with api. So visit the project page at github and download the yos-social python library. Follow the installation instructions and let´s try to get some flat info from YQL, try this on the python console:

PYTHON:
  1.  
  2. import yahoo.yql as yql
  3. yqlQuery = "SELECT price FROM nestoria.search WHERE place_name='Pimlico' and price_max='250' and listing_type='rent' and country='uk'"
  4. yql.YQLQuery().execute(yqlQuery)
  5. {u'query': {u'count': u'20', u'lang': u'en-US', u'updated': u'2009-08-19T10:27:47Z', u'created': u'2009-08-19T10:27:47Z', u'uri': u'http://query.yahooapis.com/v1/yql?q=SELECT+price+FROM+nestoria.search+WHERE+place_name%3D%27Pimlico%27+and+price_max%3D%27250%27+and+listing_type%3D%27rent%27', u'results': {u'listings': [{u'price': u'190'}, {u'price': u'210'}, {u'price': u'225'}, {u'price': u'190'}, {u'price': u'225'}, {u'price': u'240'}, {u'price': u'250'}, {u'price': u'103'}, {u'price': u'173'}, {u'price': u'249'}, {u'price': u'225'}, {u'price': u'225'}, {u'price': u'230'}, {u'price': u'200'}, {u'price': u'230'}, {u'price': u'185'}, {u'price': u'195'}, {u'price': u'165'}, {u'price': u'250'}, {u'price': u'195'}]}, u'diagnostics': {u'user-time': u'317', u'publiclyCallable': u'true', u'url': [{u'content': u'http://datatables.org/alltables.env', u'execution-time': u'4'}, {u'content': u'http://www.datatables.org/nestoria/nestoria.search.xml', u'execution-time': u'6'}, {u'content': u'http://api.nestoria.co.uk/api?action=search_listings&encoding=xml&has_photo=1&place_name=Pimlico&price_max=250&listing_type=rent&page=0&number_of_results=20', u'execution-time': u'293'}], u'service-time': u'303', u'build-version': u'2579'}}}
  6.  

Cool, so we can get the info in a easy way. » Read the rest of this entry «

Where Am I?

You are currently browsing entries tagged with yql at arde en el infierno.