

String appid = "YbULhZfV34ERqMXMNQP14Opd68RDsU1n0hhNy_kyqZIKEWGJKYNOa7YgWtfmfvs-";
PFont f;
Bubble[] bubbles = new Bubble[1];
SearchClient client = new SearchClient(appid);
void setup() {
size(1200,1200);
bubbles[0] = new Bubble("",0,1000,1000);
f = loadFont("Georgia-24.vlw");
textFont(f);
smooth();
}
void draw() {
background(100);
String searchquery = "processing opengl";
performsearch(searchquery);
noLoop();
}
void performsearch(String query)
{
WebSearchRequest request = new WebSearchRequest(query);
// (Optional) Set the maximum number of results to download
request.setResults(3);
try {
WebSearchResults results = client.webSearch(request);
// Print out how many hits were found
println("Displaying " + results.getTotalResultsReturned() +
" out of " + results.getTotalResultsAvailable() + " hits.");
println();
// Get a list of the search results
WebSearchResult[] resultList = results.listResults();
// Loop through the results and print them to the console
for (int i = 0; i < resultList.length; i++) {
// Print out the document title and URL.
println((i + 1) + ".");
println(resultList[i].getTitle());
println(resultList[i].getUrl());
println();
//now print the content from this specific url
String urlpath =resultList[i].getUrl();
URL url = new URL(urlpath);
InputStream stream = url.openStream();
//Create a BufferedReader from the InputStream
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line;
int printcount=0;
while ((( line = reader.readLine()) != null)&&(printcount<10)) {
//draw a bubble for this url and the top 20 lines scraped from it
//int resultList.length = 3;
float r = pow(resultList.length,0.25)*100.8;//all bubbles will be the same size
float spacing = 1.5*(width/resultList.length);
Bubble b = new Bubble(resultList[i].getUrl(), r,bubbles.length*spacing - spacing/2+100*i,300+i*300);//height-i*300-200);
b.display();
// bubbles = (Bubble[]) append(bubbles,b);
if(printcount<10)
{
text(line, bubbles.length*spacing - spacing/2+100*i,300+i*300+printcount*10);//height-i*300 +printcount*10);
fill(102, 102, 153);
textAlign(LEFT);
textFont(f, 12);
print(line+"\n");
printcount++;
}
}
// Close the reader
reader.close();
}
// Error handling below, see the documentation of the Yahoo! API for details
}
catch (IOException e) {
println("Error calling Yahoo! Search Service: " + e.toString());
e.printStackTrace();
}
catch (SearchException e) {
println("Error calling Yahoo! Search Service: " + e.toString());
e.printStackTrace();
}
}
No comments:
Post a Comment