fredag 22. januar 2010

Google blogger integration

So, a first blog with some relative meaning to it..

Alright, theres a million ways to integrate a blog. But you want a fast and clean code integration right? Preferably using python? Well, here it is...

Google offers a python client library for the Google data API's, witch has a blogger module. There is an egg available over at pypi, and some outdated documentation on the googlecode site.

Obtaining the API wrapper - the gdata python client library

The simplest way to get the gdata python client is to install it using easy_install.

$ easy_install gdata

Using the gdata python client library

First, lets go through the interesting bit - how to use the gdata client to get your blogs.

import gdata.blogger.client

# Get a client and log in
client = gdata.blogger.client.BloggerClient()
client.client_login('googleaccount_username',
'googleaccount_password',
source='someuserorcomp-someapp-1.0',
service='blogger')

# Build the query.
query = gdata.blogger.client.Query(order_by='updated')

# Request the feed.
feed = client.get_posts(self.blog_id, query)

# Get the blogs.
blogs = []
for entry in feed.entry:
blog = {}
blog['title'] = entry.title.text.encode('utf-8')
blog['link'] = entry.GetHtmlLink().href
blog['content'] = entry.content.text.encode('utf-8')
blogs.append(blog)

# Print the results.
print blogs


Its pretty straight forward.

Remember to only do the client_login bit once ( !!not for every request if your building a web app!! ) and to put restraints in the query to limit load and the amount of data transferred.

For a strings example, check out this page.

enjoy.

onsdag 20. januar 2010

A first attempt at blogging

This a first attempt at writing a blog.

Should be simple enough? Ok, write about what your doing...

I'm currently building my new website http://asbjornenge.com. It will contain information about the different things I spread the hours of my life across. I'm building my new website in a WSGI wrapper I'm working on, called strings.

I had the idea that the website should contain a blog if I suddenly came to feel like writing down some thoughts or release information or other things like that. Building a blog with strings would be pretty straight forward, but now-a-days its all about integration, isn't it?

So, thats about it really. Let's give it a spin.