« Babeldoc. | Main | The big day! »

Technoratj

Well, this was inevitable. (Background: Technorati API released.)

Remember that whole not-taking-on-new-projects thing? Well, somebody else said that, not me. Which, honestly, is obvious to those who read that other RTP blogger.

Open source, Apache-licensed. Share and enjoy.

;-)

After looking at Mark Pilgrim's PyTechnorati and seeing how little Python code is needed to wrap the Technorati API (one file with 171 lines, not including the header comments), I developed a case of language envy. I decided to see what I could do with Java, JDOM, XPath, and a couple of inner classes. Technorati.java is the result (get the project here: technoratj.zip). My wrapper is about the same size as PyTechnorati, but it does not handle HTTP proxies as Mark's does (is there a FancyURLOpener for Java?). Seeing PyTechnorati also inspired me to revisit Jython. Here is how you'd use technoratj from Jython:

Jython 2.1 on java1.4.1_01 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> from org.roller.technorati import Technorati
>>> technorati = Technorati("YOUR_KEY")
>>> cosmos = technorati.getLinkCosmos("http://rollerweblogger.org/page/roller")
>>> cosmos.weblog.name
'Blogging Roller'
>>> cosmos.weblog.rssurl
'http://www.rollerweblogger.org/rss/roller'
>>> cosmos.weblog.inboundblogs
33
>>> cosmos.weblog.inboundlinks
44
>>> for blog in cosmos.weblogs:
...     print blog.name
...
BlogAtom
Erik's Weblog
Feelings and Thoughts
Quidnunc
Hacking Log 3.0: America's Blog
...

Note: I had to provide an EntityResolver and my own copy of the technorati.dtd because Technorati results sometimes contain mdash entities and mdash is not in Dave Sifry's DTD. The Technorati API can return malformed XML (I've seen ampersands in name and excerpt elements) and this is a problem for my wrapper. Is the Python MiniDOM more lenient about these issues?

Comments:

As you are using Sun's URLConnection, you can take advantage of the built-in proxy system properties. Here is some code from nntp//rss to give you an example: // Assumes the following variables... // proxyServer - proxy server hostname // proxyPort - string containing proxy port // proxyUserID and proxyPassword - optional // proxy username / id credentials if ((proxyServer != null) && (proxyServer.length() > 0)) { System.setProperty("http.proxyHost", proxyServer); System.setProperty("http.proxyPort", Integer.toString(proxyPort)); System.setProperty("http.proxySet", "true"); if ((proxyUserID != null && proxyUserID.length() > 0) || (proxyPassword != null && proxyPassword.length() > 0)) { Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(proxyUserID, (proxyPassword == null) ? new char[0] : proxyPassword.toCharArray()); } }); } else { Authenticator.setDefault(null); } } // end of code... Note - For the next release of nntp//rss, I have actually ripped out this code and the usage of HttpUrlConnection and replaced it with the Jakarta Commons HTTPClient. Sun's HttpUrlConnection (especially pre JDK 1.4) has a couple of issues dealing with timeout scenarios.

Posted by Jason on May 17, 2003 at 04:24 PM EDT #

re: Is the Python MiniDOM more lenient about these issues? No

Posted by Sam Ruby on May 17, 2003 at 07:07 PM EDT #

Great comments guys. Peter FDA

Posted by Peter on November 11, 2003 at 04:39 AM EST #

Post a Comment:
  • HTML Syntax: NOT allowed

« Babeldoc. | Main | The big day! »

Welcome

This is just one entry in the weblog Blogging Roller. You may want to visit the main page of the weblog

Related entries

Below are the most recent entries in the category Java, some may be related to this entry.