http://www.redmonk.com/jgovernor/2007/08/03/on-blogging-no-niche-required/
Ongoing musings, tips, and observations from a Van Couvering, not someone who is going to Vancouver.
Showing posts with label blogging. Show all posts
Showing posts with label blogging. Show all posts
Friday, August 03, 2007
To niche or not to niche
James Governor quotes Anne Zelenka on the value of "niching" your blog. I like talking about just about everything, but I have to agree with my bro that posting lots of family stories and photos is going to drag down a "general reader" blog.
Wednesday, June 27, 2007
Quick Tip: Making code readable in Blogger
My last post included some source code, and I really struggled how to make this look readable.
I use NetBeans, and I checked, and sure enough, there is an option to export a source file or a selection of source to HTML ("File->Print to HTML..." in NetBeans 6).
This takes care of all those nasty less-than / greater-than conversions. It also sets up some styles and applies those styles to the code, so you get readable code through color-coding.
The trick is, NetBeans generates this as a complete HTML page. But I want to embed this in an existing page. This worked generally, but the styles were lost.
After some thought, what I did was edit the HTML for my template, and then added the styles at the top of the NetBeans generated page to the styles for the template. And voila, I have nice, color-coded source code that is a simple cut-and-paste from NetBeans.
I use NetBeans, and I checked, and sure enough, there is an option to export a source file or a selection of source to HTML ("File->Print to HTML..." in NetBeans 6).
This takes care of all those nasty less-than / greater-than conversions. It also sets up some styles and applies those styles to the code, so you get readable code through color-coding.
The trick is, NetBeans generates this as a complete HTML page. But I want to embed this in an existing page. This worked generally, but the styles were lost.
After some thought, what I did was edit the HTML for my template, and then added the styles at the top of the NetBeans generated page to the styles for the template. And voila, I have nice, color-coded source code that is a simple cut-and-paste from NetBeans.
Blogging delicious links
I've really been enjoying Simon Phipp's delicious bookmarks. Its actually one of my favorite feeds.
I like this much better than the "daily links" approach, where I have to open the blog and read them all together. I usually don't bother to open "daily links" blog entries, because the majority of the time there's nothing there of interest for me. With a blog per link, I can quickly scan and pick the ones I like.
That got me thinking, wouldn't it be nice if I could simply tag a link with a quick comment, and have it show up automatically in my Blogger/Blogspot blog? I'm not a big linker, I don't do tens a day, so it shouldn't overwhelm my readers...
Well, delicious doesn't support this capability. But with a little work, I was able to use their APIs and the Google Blogger/GData APIs to accomplish this. And I thought I'd share the code with you. You could probably pretty easily convert this to using other blog platform APIs.
With this in place, now when I want to do a quick blog of an interesting link, just tag it with "blogthis" and run this program. I can run it once for each tag, once a day, or even less frequently. Once all the posts have been blogged, the tag is renamed to "blogged" so that I don't keep blogging the same posts.
There is some preparatory work needed before you can compile and run the code I show below.
First, you need to download the Java client libraries for both the Delicious API and the Google Data APIs. The Delicious API was incredibly simple to navigate; the GData APIs not so. Somehow their documentation is just lightweight and obtuse enough to leave you scratching your head. Maybe they want to use it for interview tests :). Anyway, I finally made my way through and got something working.
Next, you need to get all of the dependent jar files. Ye gods, there are a lot of them. Here they are:
The delicious Java client requires
Then the Google Data client library requires
Finally, you need to get the id for your Blogger blog. To do this, simply go to your blog, view the HTML source, and look for this line:
The href attribute is what you use as the postURL for Google Data.
I am using the ClientLogin mode of authentication with Google Data. This mode says it may reject the authentication request and ask for a Captcha response. I didn't want to deal with this, and you can register a particular machine to no longer need Captcha. Since this is for your personal use, this seems a reasonable thing to do. For more information on ClientLogin authentication, see this page.
OK, whew, with that taken care of, here is the fairly simple code to suck down delicious posts tagged with "blogthis" and posting them to my blog.
Make sure you replace the placeholders for the delicious username and password, Blogger username and password, and the postURL.
I like this much better than the "daily links" approach, where I have to open the blog and read them all together. I usually don't bother to open "daily links" blog entries, because the majority of the time there's nothing there of interest for me. With a blog per link, I can quickly scan and pick the ones I like.
That got me thinking, wouldn't it be nice if I could simply tag a link with a quick comment, and have it show up automatically in my Blogger/Blogspot blog? I'm not a big linker, I don't do tens a day, so it shouldn't overwhelm my readers...
Well, delicious doesn't support this capability. But with a little work, I was able to use their APIs and the Google Blogger/GData APIs to accomplish this. And I thought I'd share the code with you. You could probably pretty easily convert this to using other blog platform APIs.
With this in place, now when I want to do a quick blog of an interesting link, just tag it with "blogthis" and run this program. I can run it once for each tag, once a day, or even less frequently. Once all the posts have been blogged, the tag is renamed to "blogged" so that I don't keep blogging the same posts.
There is some preparatory work needed before you can compile and run the code I show below.
First, you need to download the Java client libraries for both the Delicious API and the Google Data APIs. The Delicious API was incredibly simple to navigate; the GData APIs not so. Somehow their documentation is just lightweight and obtuse enough to leave you scratching your head. Maybe they want to use it for interview tests :). Anyway, I finally made my way through and got something working.
Next, you need to get all of the dependent jar files. Ye gods, there are a lot of them. Here they are:
The delicious Java client requires
Then the Google Data client library requires
Finally, you need to get the id for your Blogger blog. To do this, simply go to your blog, view the HTML source, and look for this line:
<rel="service.post" href="http://www.blogger.com/feeds/NNNNNNN/posts/default">
The href attribute is what you use as the postURL for Google Data.
I am using the ClientLogin mode of authentication with Google Data. This mode says it may reject the authentication request and ask for a Captcha response. I didn't want to deal with this, and you can register a particular machine to no longer need Captcha. Since this is for your personal use, this seems a reasonable thing to do. For more information on ClientLogin authentication, see this page.
OK, whew, with that taken care of, here is the fairly simple code to suck down delicious posts tagged with "blogthis" and posting them to my blog.
Make sure you replace the placeholders for the delicious username and password, Blogger username and password, and the postURL.
import com.google.gdata.client.GoogleService;
import com.google.gdata.data.Category;
import com.google.gdata.data.Entry;
import com.google.gdata.data.PlainTextConstruct;
import del.icio.us.Delicious;
import del.icio.us.beans.Post;
import java.net.URL;
import java.util.List;
public class Main {
public static void main(String[] args) {
try {
Delicious deli = new Delicious("your-delicious-userid", "your-delicious-password");
List<Post> posts = deli.getPostsForTag("blogthis");
for ( Post post : posts ) {
System.out.println("Blogging post: " + post.getDescription());
blogPost(post);
}
deli.renameTag("blogthis", "blogged");
System.out.println("All delicious posts blogged");
} catch ( Throwable e ) {
e.printStackTrace();
}
}
private static void blogPost(Post post) throws Exception {
// authenticate
GoogleService service = new GoogleService("blogger",
"david.vancouvering.delicious-blog");
service.setUserCredentials("your.google.user.id", "your-google-password");
// build entry
URL postURL =
new URL("http://www.blogger.com/feeds/your-numeric-id/posts/default");
Entry entry = new Entry();
entry.setTitle(new PlainTextConstruct("Quick Link: " + post.getDescription()));
StringBuffer buf = new StringBuffer();
if ( post.getExtended() != null ) {
buf.append(post.getExtended());
buf.append("<p>");
}
buf.append("<a href=\"" + post.getHref() + "\">" + post.getHref() + "</a>");
entry.setContent(new PlainTextConstruct(buf.toString()));
// Set the label for the entry
Category category = new Category();
category.setScheme("http://www.blogger.com/atom/ns#");
category.setTerm("quicklink");
entry.getCategories().add(category);
// post entry
service.insert(postURL, entry);
}
}
Subscribe to:
Posts (Atom)