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 › does delay() work with the del.icio.us lib?
Page Index Toggle Pages: 1
does delay() work with the del.icio.us lib?? (Read 743 times)
does delay() work with the del.icio.us lib??
Jun 1st, 2006, 6:51am
 
i've moved this post out of syntax since this is probably a more appropriate spot for it.


Hi,
I'm writing a program that downloads my bookmarks, alters some tags and then sends the updated bookmark to del.icio.us.

I am using David Czarnecki's library (and some of the demo code from http://www.processinghacks.com/hacks/delicious ).

Everything works except for the delay. There needs to be at least a 1 second delay between calls to the del.icio.us api and I am using delay(2000).

My problem is that the program runs at the same speed if I use delay(2000), delay(10000) or no delay at all.

Is the lack of delay related in anyway to the fact I'm using a library? Is there a better way of implementing a delay?

I just think it's pretty funny that I'm usually cursing the slow speed of my apps and now I'm having the entirely opposite problem, haha!
Re: does delay() work with the del.icio.us lib??
Reply #1 - Jun 4th, 2006, 1:14am
 
Here's some code to illustrate the difficulty I'm having.

I'm trying to download my bookmarks and add a few tags.
Everything works fine until I get to the 29th bookmark and then it stalls with no response from del.icio.us (regardless of what the bookmark is).

In this example code I'm adding 'deleteLater' as a tag to illustrate the issue.

If you want to run this yourself you'll need to download the library (with dependencies) from here http://sourceforge.net/projects/delicious-java/

Or, you can download my sketch folder here http://boydstudio.ca/p5/deliciousExample1.zip

I'm totally stuck so any suggestions are very welcome.

(Non forum mangled version of the code can be seen here)

Code:

/**
* I've used some code from Marius Watz's example found
* here http://processinghacks.com/hacks:delicious
* (specifically the connection code and casting the bookmarks as Post objects)
*/

Delicious delicious; // create Delicious object called delicious (ooh the originality!)
Object[] o; // simple object array to be used to hold the bookmark posts to be downloaded from delicious
Post[] posts; // Post array to eventually hold the bookmark posts (after they're cast into Post objects)
String newTag = "deleteLater"; // for the purposes of this example this is a new tag I want to add to all my bookmarks

int currentPost = 0; // current post being used
int startTime; // obvious

void setup() {
// Initiate Delicious object. Replace username and password with your own info.
delicious=new Delicious("yourUsername","yourPassword");
delay(2000);
// add in a delay ensure we're not breaking the 1 transaction/second rule


// I doubt its necessary here but im adding it in to be safe.

getMyPosts(); // function to go and grab some bookmarks

startTime=millis(); // set startTime to equal the time after the bookmarks have been grabbed.
println("");
for(int i = 0; i < posts.length; i++) { // run through each post

float telp=(millis()-startTime)/1000.0; // telp = total elapsed time since the grabbing the bookmarks

println("--------------+---------------");

println("Processing post number "+i+" of "+posts.length);

println("time elapsed since start: "+telp+" seconds.");

processPost(posts[i]);

println("");

println("");

}
}

void draw(){} // vestigial draw function. nothing doing here. everything happens in setup

void getMyPosts(){
// Choose one of the two lines below for getting either all the posts just a subset of the posts
// o=delicious.getAllPosts().toArray();
o=delicious.getRecentPosts("",35).toArray();
delay(2000); // add in a delay ensure we're not breaking the 1 transaction/second rule


// again probably but adding it anyway


// Convert the Objects to Posts
posts=new Post[o.length]; // set the size of the Post array
println("Del.icio.us posts retrieved: "+posts.length);
for(int i=0; i<posts.length; i++) posts[i]=(Post)o[i]; // cast the bookmark Objects as Post objects
// back to setup()
}


// process one post at a time
void processPost(Post _post){
Post currPost = _post; //currPost is the post we're operating on atm
String[] tags = currPost.getTagsAsArray(" "); // grab the tags for this post into an array called tags
String tagString="";
for(int i = 0; i < tags.length; i++) tagString+=tags[i]+" ";
tagString += newTag; // add the new tag to the tag list
updatePost(currPost, tagString); // send this post and its new set of tags to be updated
}

void updatePost(Post _p, String _cts){
Post p = _p;
String cts = _cts;

p.setTag(cts); // set the new tags for this post object

println("run time just before update is sent to del.icio.us is: "+(millis()-startTime)/1000.0);
boolean sent = delicious.addPost(p.getHref(), p.getDescription(), p.getExtended(), p.getTag(), p.getTimeAsDate(),true,true);
// the above line (hopefully) updates the post to del.icio.us using the addPost method.
delay(2000); // again, delay for 2 secs to avoid getting throttled.
println("run time after sending the addPost update and running 2 sec delay: "+(millis()-startTime)/1000.0);
println(" ");
}

Page Index Toggle Pages: 1