Jul 15
Marking your del.icio.us boomarks as private using ColdFusion
Posted by James Netherton | Sunday 15 July 2007 7:29 PM | In ColdFusion
del.icio.us is my tool of choice to manage all of the various bookmarks that I collect on a day-to-day basis. I've noticed for a while that search engines are able to spider a persons boomkmark page and list the results. Also, other sites seem to be aggregating links from del.icio.us and other online bookmarking tools.
I'm not all that bothered whether search bots spider my bookmarks or not, but it's starting to get annoying when I search for something and I'm presented with one or many of my bookmarked URL's within the top set of results!
A while back, del.icio.us introduced a feature that lets you flag a bookmark as 'not for sharing'. This was fine for future bookmarks, but what about the hundreds of others that I have collected? It's not practical to manually update every single item individually.
Fortunately, del.icio.us exposes an API which allows you to easily manipulate all of the bookmarks and tags in your collection. Here's how I used it with the help of ColdFusion, to mark all of my bookmarks as private. Notice that I'm using the new ColdFusion 8 convention for looping over arrays.
<cfapplication name="makedelicioustagsprivate"/>
<cfif not structKeyExists(application,"bookmarks")>
<!--- Get all bookmarks --->
<cfhttp method="post" url="https://api.del.icio.us/v1/posts/all" username="username" password="password">
<cfhttpparam type="formfield" name="dummy" value=""/>
</cfhttp>
<!--- Craete a XML DOM object if the request was ok --->
<cfif cfhttp.statusCode eq "200 OK">
<cfset application.bookmarks = xmlParse(cfhttp.FileContent)/>
<cfelse>
<cfdump var="#cfhttp#"/>
<cfabort/>
</cfif>
</cfif>
<!--- Get the bookmark links --->
<cfset variables.bookmarkLinks = xmlSearch(application.bookmarks,"//posts/post")/>
<!--- Lets us add in a delay after each request --->
<cfset objThread = createObject("java","java.lang.Thread")/>
<!--- Loop over the bookmarks and mark them as private --->
<cfloop array="#variables.bookmarkLinks#" index="variables.bookMark">
<cfhttp method="post" url="https://api.del.icio.us/v1/posts/add" username="username" password="password">
<cfhttpparam type="formfield" name="description" value="#variables.bookMark.xmlAttributes.description#"/>
<cfhttpparam type="formfield" name="url" value="#variables.bookMark.xmlAttributes.href#"/>
<cfhttpparam type="formfield" name="replace" value="yes"/>
<cfhttpparam type="formfield" name="shared" value="no"/>
<cfhttpparam type="formfield" name="tags" value="#variables.bookMark.xmlAttributes.tag#"/>
<cfhttpparam type="formfield" name="dt" value="#variables.bookMark.xmlAttributes.time#"/>
</cfhttp>
<cfif cfhttp.statusCode neq "200 OK">
<cfoutput>Failure : #variables.bookMark.xmlAttributes.href#<br/></cfoutput>
</cfif>
<cfset objThread.sleep(2000)/>
</cfloop>
The code above is pretty simple. It retrieves all of my bookmarks and updates them setting the shared attribute to 'no'. Some things to note:
- Just in case something fails, I cache the initial list of bookmarks in application scope. The request to get them is quite intensive and I got blocked from making requests to the service after I had made several requests in quick succession
- The API requires that you leave a 1 second gap between requests. I have used the Java Thread object to enforce a 2 second gap between bookmark update requests
- In accordance to the above, you'll need to set an appropriately long request timeout value
- Obviously if you have lots of bookmarks and don't adjust the 2 second gap between requests, the process is going to take a while!
If there's some glaringly obvious way to do all of this via the del.icio.us preferences, let me know and I'll stop wasting my time writing pointless code!
0 Comments
[Post comment]