From the Burrow

Fun with Tags

2011-08-26 00:00:00 +0000

As I mentioned a few posts back, tags are a bit weird. I had assumed that you would be able to query for a list of posts belonging to a certain tag but apparently not.

What I have gone for instead is to scrape the rss feed for the tag, and from that grab the post ids.

As there could be hundreds the call returns post objects which behave like dicts but can retrieve the data from the server as it is accessed.

So to grab all the posts tagged ‘python’ and print the body text of the first post you can do this:


tagged_posts = blog["python"]

print tagged_posts[0]["body"]

Simple!

Editing a post

2011-08-26 00:00:00 +0000

Here’s what you do to change a post’s title with my library:

# get most recent post

post = blog[0]



# edit the posts title

post.title = "hey a new title!"



# push post back to blog

blog[0] = post

Tags are an interesting beasty with wordpress, I can’t query for all posts with a tag, but I can get the rss feed for a tag, so I’m hoping I can pull the info from there.

Will keep ye posted

API Changes

2011-08-26 00:00:00 +0000

Hey folks,

Made some changes to keep things a native as possible.

Posts behave as dicts now, to make a post you now just have to write:


post= {"title": "example title",

		"body": "example body text",

		"tags": ["wordpress", "api", "python"],

		"live": True}

blog.append(post)

Internally the library uses a dict like object to present posts but that is just so that some data can be retrieved lazily.

I’m close to an beta release now so I’m really going to have to hurry up and get on launchpad!

test post

2011-08-25 00:00:00 +0000

Test text New line Conclusion…BYE!

anther test

2011-08-25 00:00:00 +0000

Well this is boring!

The simple Wordpress Library in practice

2011-08-25 00:00:00 +0000

Ok so here is how you make a simple post using the new python library I’m writing


import wpress



blogs = wpress.WP("https://cbaggers.wordpress.com/xmlrpc.php",

                   "username", "password")



blog = blogs["Baggers on the Web"]





new_post  = wpress.WPPost()



new_post.title = "First Post Test!"

new_post.body = """Hey all!

This is my first live test of my python library. 

In the next post I will show the code used to post this post.

Wooo!"""

new_post.tags=["wordpress","python"]

new_post.live=True



blog.append(new_post)

That’s all there is to it! When you connect to wordpress a dict of your blogs is returned, you pull out the one you want and append on a post.

If you want to pull the first 6 posts you do this


import wpress



blogs = wpress.WP("https://cbaggers.wordpress.com/xmlrpc.php",

                   "username", "password")



blog = blogs["Baggers on the Web"]



first_six = blog[:6]

I’m crashing out now but I’m going to post on working with xmlrpc in general soon…there have been some interesting gotchas.

Goodnight!

Need a mapping of SQL Version Numbers to Release and SP?

2011-08-25 00:00:00 +0000

I did…and I found it here

My reading for tonight

2011-08-25 00:00:00 +0000

This looks like about the best place to start on my road to Ubuntu development: Getting Started with Ubuntu Development

Cheers to dholbach and everyone in the Ubuntu developer week. I’ll post back how this goes.

LDAP and Binding to a specific server

2011-08-25 00:00:00 +0000

Hey all,

I was looking into the uSNChanged value in ldap and saw that (at least in AD) it is not replicated. This meant I would have to query each server individually…then I realised I didnt know how!…turns out I’ve been connecting just by domain, so a quick google later and I found this:


	"LDAP://servername/dc=work,dc=co,dc=uk"

Nice!

Implement 'slice' in a custom Python object

2011-08-25 00:00:00 +0000

I needed to do this a little while back while making a pythonic circular list. There used to be a command called getslice but this was deprecated a good while ago and replaced with something (in my opinion) more elegent: slice objects.

Read all about it here! (this doco is a little old, but communicates the principles well)