Can I Java cup of coffee? Isn't that valid?
Yesterday I made some progress on the twitter-exporter tool, working and thinking quite a bit in one day.I'm surprised I am as productive as I am in Java, since I haven't used it in work-related projects. Yesterday it felt like I had a couple of cups of coffee too many, maybe it's the spring, but I was cranking out code and dealing with Exceptions like I'd been eating a lot of cake and drinking a lot of coffee.
I'm particularly pleased with this piece of code:
class TwitterStatusFetcher {
Twitter twitter;
ArrayList statuses = new ArrayList();
Integer page = 1;
Integer count = 20;
TwitterStatusFetcher(Twitter twitter_) {
twitter = twitter_;
}
Status getNextStatus() throws TwitterException {
if (statuses.isEmpty()) {
// See if more tweets can be found
ResponseList results = twitter.getUserTimeline(
new Paging(page, count));
page++;
statuses.addAll(results);
}
if (statuses.isEmpty()) {
return null;
}
Status status = (Status) statuses.get(0);
statuses.remove(0);
return status;
}
}
Which works with the twitter4j code and Twitter API to deliver one status at a time to the rest of my app code. Maybe it's not that big of a deal, but I found it elegant, and it does use the object-oriented paradigm that Java is big on.
It seems the most frequent mistake I make coming from Python, is forgetting the semicolon; I like to indent code regardless of language, so it's the semicolon that I forget.
I guess one thing I've found annoying about Java so far, is the type casting that is necessary at different places. I was working on some code which I guess was eventually removed, where I knew the method to call, but because of some abstraction in a method call, the returned objects were java.lang.Object, and calling a method, a String method I think, on that object failed in compilation.
I was also almost smacking my head yesterday, when I discovered that twitter4j returns shortened (and expanded) URLs in their Tweets as well, and thought I'd developed quite a bit of code for no good reason.
However, as it turns out, some tweets do contain shortened URLs that aren't mentioned in the Tweet metadata, so the class I wrote to resolve t.co URLs still has some use. Phew.
Finally, I found Firefox now displayed the test.html output page as XML, instead of XHTML. So I made the code output a Unicode BOM, and Firefox says it is in standards compliance mode, and Chrome does not complain. However, the validator on w3c.org, https://validator.w3.org/ - still does not validate the page when it has a UTF-16LE BOM.
I'm not sure what's going on there, but to me it looks like the w3c validator isn't working.
A test.html page I just created is available at http://blogologue.com/test2.html.bin - just rename it to test2.html after download and open it in Firefox to see the rendered archive of my tweets.
[Permalink] [By morphex] [A Java-based tool to export tweets from Twitter for safe keeping (Atom feed)] [14 Apr 10:35 Europe/Oslo]