Tuesday, November 20, 2007

Lab 4: Finished

This lab really was quite simple because doing all the previous labs gave me the necessary tools to do this one. I found two libraries for akismet. Use this one as the other always returns spam="true"; which drove me nuts.

GUID worked well.

Finished Lab3

The submit process was my greatest difficulty for this lab. I was clueless on how Python gets post variables and a bit confused on the submit script. After talking with Sam, I was able to complete it and was surprised how easy these were.

to get post variables (var1, var2, ...):

def index(req, var1="", var2="", . . . ):

Submitting was a bit more tricky, but I just had to use urlencode(data{}) from the urllib to encode the data dictionary of variables. Then use urllib.urlopen(url, urlencoded(data{})).
docs.python.org has a good example. What confused me was trying to use the http library that someone recommended for doing posts in python.

Friday, November 9, 2007

Still Working on Lab3

Well, I'm getting there. I pretty much have the index and domain pages displaying properly now. The trick was finding out how to use XML in python. I tried Amara, but the installation failed. So, I decided to try ElementTree. I didn't have to install anything to use it. It was a bit tricky to understand how to use it at first, but it really isn't that bad.

Here's an example:

from elementtree import ElementTree
tree = ElementTree.XML('some xml string')

# find all nodes with tag
for node in tree.getiterator('domain'):
# get attribute ideacount's value
ideacount = node.get('ideacount')

# get text between the tags
domain = node.text

# find child node of foo where tag =
foo = node.find('submit')
tech = foo.get('technology') #get technology attribute

Now I just have to work on the submit process.