Quick Tutorial: YQL + Pipes Working Together

Editor's note: This Guest Post blog post comes from Darren Levy, who's earning a Masters in Computer Science at New York University. This past December, he received an honorable mention for his YQL + Kynetx app, FaceTheMusic, and always enjoys learning about cool new web technologies.

If a friend sent you to this blog post, then he or she wants to show you how easy it is to start programming. Yahoo! provides lots of products that offer almost instant gratification and require no prior programming experience. Just a little time here will give you a whole new set of tools at your disposal.

In this tutorial, we will go over how to combine Yahoo! Pipes and Yahoo! Query Language (YQL).

If you go to the YQL console, click “Show Community Tables” and scroll through, you can instantly see all the information YQL can access. A good way to learn how to write YQL statements is to click on the "Example Queries" right above the data tables.

Let’s say we wanted to use the Newegg.com data table to create an item search. Here is the YQL statement:
select * from newegg.search where query="LCD TV"

If we put that into the console and hit Test, we’ll see the XML file returned beneath it, which contains all the items that match our search.

Let’s bring this into Yahoo! Pipes.  First, create a new Pipe by going to pipes.yahoo.com and click “Create a pipe.” On the left you’ll see a bunch of different categories and modules within those categories. To find out what a module does, click it and a description will appear in the lower left. To use the module, click and drag it to the right onto the grid area. Begin by dragging out a YQL module (under Sources) and a Loop module (under Operators). Next, drag an Item Builder module (under Sources) onto your Loop module.

Now we can link the YQL module to the Loop and the Loop to the Pipe Output. To link, just click the circle at the bottom of one module and drag it to the circle at the top of the other.

In the YQL module where it says “Enter your Query:” put the YQL statement we created:
select * from newegg.search where query="LCD TV"

Under Attributes in the Item Builder module, type in title and set it equal to item.name. Then add another Attribute by clicking the plus sign and type in link and set that equal to item.link. Finally, click the radio button next to “emit all results.” This will ensure our output will only have the name of the product in the title and a link to it. Check out the screenshot:

screenshot of pipespipes1

Bascially, what we have here is a YQL statement that gives us the results from a Newegg search. Then our Loop module looks at every item in the search and the Item Builder saves just the product name and link.

At this point, if you click the Pipe Output module, you should be able to see the results in the Debugger window. But what if you don’t just want to search for LCD TVs?

Drag two more modules out near your YQL module: String Builder (under Strings) and Text Input (under User Input).

In the String Builder module, click the plus sign twice. Then connect the String Builder to the YQL module’s query box and connect the Text Input module to the second String Builder box.

As the Default value of the Text Input, let’s put netbook.

In the String Builder’s first box, put the part of the YQL statement before the actual query:
select * from newegg.search where query="
In the third box put the rest of the statement after the query:

Here's a screenshot: pipes2pipes 2pipes2

If we Save the pipe and click “Run Pipe...” you should be brought to a page that looks very similar to this one:

Feel free to replace netbook with whatever you want and click “Run Pipe” and you will see search results.

Note: If it doesn’t work right away, trying refreshing the page.

From here, you could use the Yahoo! User Interface Library (YUI) to put a search box on your site and even use Yahoo! Pipes to add your referral ID to all the links.

Darren LevyDarren Levy (@darrenlevy)
Developer of Face the Music
Guest Blogger