We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProcessing DevelopmentLibraries,  Tool Development › Library for Yahoo BOSS Mashup
Page Index Toggle Pages: 1
Library for Yahoo BOSS Mashup? (Read 624 times)
Library for Yahoo BOSS Mashup?
Oct 1st, 2008, 1:15pm
 
Hey all

Has anyone any recently updated Yahoo library?
Or rather a simplified approach to deal with the contest at Yahoo BOSS Mashup thing...
http://developer.yahoo.com/search/boss/mashup.html

I am a bit curious to pitch an old idea, but they insist that their BOSS Mashup-whatever-API should be used. I tried to call them and say that they forgot a language in their list of supported languages, but they hang up on me Smiley

Just curious to participate in the Build Your Own Search Engine which I really don't want to, just the presentation of the actual search. With Processing as devTool thank you very much. The deadline is october 5:th, so I don't have the time to learn Ruby or Python or pure Java which is on my list... Smiley

Any thoughts or ideas of how to approach this?

/Johan
Re: Library for Yahoo BOSS Mashup?
Reply #1 - Oct 2nd, 2008, 9:29am
 
I made a quickfix for it myself with the Javcode found on Yahoo. I don't know Java, but this seemed to work. Hey, thanks Processing!

You can only search with one word... uhm... not great, but still. Take it from here. It is a really dirty hack, but it works unless you test it extensively. It is not tested etc... I'm on a mac.
If you get how to make decent queries (meaning more than one word :-) please post. I'm out of time here :-) Hope someone finds this helpful as a start...

Here's the code:
/*
Quick and Dirty access to Yahoo Boss search
More info on Yahoo Boss http://developer.yahoo.com/search/boss/
PRESS MOUSE AND THE SEARCH STARTS.
The result is parsed via XML and printed to the console
The querything is weird since it is a url - MEANING no empty spaces in the search...
Anyone got a fix, welcome to post the fix for this. Probably found somewhere on developer.Yahoo.com.
Not sure if you need a API-key, maybe this is the problem...?
It works without this way...
I said Quick and Dirty :-)
*/

import processing.net.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import java.io.*;
import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.*;

String newSearch;
int numSearches = 15;
color white = #ffffff;

void setup() {
 size(200, 200);
}

void draw() {
 background(white);
}

void mousePressed() {
 newSearch = "Processing";
 try {
   searchIt("http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=" + newSearch + "&results=" + numSearches);
 }
 catch(Exception e) {
   e.printStackTrace();
 }

}

void searchIt(String request) throws Exception{


 HttpClient client = new HttpClient();
 GetMethod method = new GetMethod(request);

 // Send GET request
 int statusCode = client.executeMethod(method);

 if (statusCode != HttpStatus.SC_OK) {
   System.err.println("Method failed: " + method.getStatusLine());
 }
 InputStream rstream = null;

 // Get the response body
 rstream = method.getResponseBodyAsStream();


 // Process response
 Document response = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(rstream);

 XPathFactory factory = XPathFactory.newInstance();
 XPath xPath=factory.newXPath();

 //Get all search Result nodes
 NodeList nodes = (NodeList)xPath.evaluate("/ResultSet/Result", response, XPathConstants.NODESET);
 int nodeCount = nodes.getLength();

 //iterate over search Result nodes
 for (int i = 0; i < nodeCount; i++) {
   //Get each xpath expression as a string
   String title = (String)xPath.evaluate("Title", nodes.item(i), XPathConstants.STRING);
   String summary = (String)xPath.evaluate("Summary", nodes.item(i), XPathConstants.STRING);
   String url = (String)xPath.evaluate("Url", nodes.item(i), XPathConstants.STRING);

   //print out the Title, Summary, and URL for each search result
   System.out.println("Title: " + title);
   System.out.println("Summary: " + summary);
   System.out.println("URL: " + url);
   System.out.println("--");

 }  
}

Page Index Toggle Pages: 1