Processing - Delicious Data Visualization

196 Views Asked by At

For a school project I'm trying to use Delicious API in Processing platform.

I have a question,

So far I can visualize the 'Titles' and 'Tags' of individual posts into the processing canvas.

My code looks like this.

    Delicious delicious;
PFont font;

String title;

void setup() {

  font = loadFont("HelveticaNeue-9.vlw");
  textFont(font);

  size(800, 1000);

  // Initiate Delicious object. Replace username and password with your own info.
  delicious=new Delicious("myusername", "mypassword");

  // Retrieve recent posts. The result is a List object containing the 
  // Posts as del.icio.us.beans.Post objects. We'll use List.toArray() to
  // give us an array of the Objects in the List.
  Object [] o=delicious.getRecentPosts("", 150).toArray();



  // Uncomment the following line to get all posts.
  //  Object [] o=delicious.getAllPosts().toArray();


  // Convert the Objects to Posts
  Post [] posts=new Post[o.length];
  for (int i=0; i<posts.length; i++) { 
    posts[i]=(Post)o[i];
  }

  // Print the posts
  println("Del.icio.us posts retrieved: "+posts.length);
  for (int i=0; i<posts.length; i++) {
    println(i+": "+posts[i]);

    pushMatrix();
    translate(50, 50);

    float descriptionWidth = textWidth(posts[i].getDescription());
    float tagWidth = textWidth(posts[i].getTag());
    int margin = 30;

    fill(50);
    text(posts[i].getDescription(), 0, 20*i);
     text(posts[i].getTime(), descriptionWidth + margin, 20*i);
    fill(135);
    text(posts[i].getTag(), descriptionWidth + margin, 20*i);
    popMatrix();
  }
}

What I want to do is, I want to get a specific get like "design" and scatter the posts' titles around that tag and draw a line from center to each of them...

But in the documentation, I cannot find a way to get a single specific Tag in the getTag() method.

The link to the documentation is here, (getTag) http://delicious-java.sourceforge.net/del/icio/us/beans/Post.html#getTag()

get the tag 'design' and type the posts' titles that contains 'design' tag around it randomly.

What is the logic behind it, can you explain it to me?

1

There are 1 best solutions below

0
fartagaintuxedo On

Since you are iterating through all the posts, use getTags() to receive a string containing the tags, check if it contains the tag u are interested in, and if yes, put the post in an array or array list. After iterating through all the posts u will have a list containing all the posts with the desired tag.