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(" ");
}