python delicious intergration
Published on April 2, 2010category: programming Tags : delicious programming python
In this post i will show how i "communicated" with delicious via python.
There are some python client libraries but i decided not to use them for learning purposes. So there is a chance that my way is not the "right" way...i am quite sure about that.
Look at delicious api at first. There are examples on how to use them using curl. As you can see you simply "hit" the url and it returns an xml which we will parse.
but no more theory , here is how i did it:
import httplib2
http = httplib2.Http()
delicious_user = ''
delicious_pass = ''
http.add_credentials(delicious_user, delicious_pass)
url = 'https://api.del.icio.us/v1/posts/recent'
response, content = http.request(url)
the above code first authenticates on delicious and the fetches my recent bookmarks.
We have to variables here, content is a string holding the xml we need to parse.
Now i'll show how you can parse it using python's minidom
from xml.dom import minidom
xmldoc = minidom.parseString(content)
postlist = xmldoc.getElementsByTagName('post')
html ="<h2> Recent from my delicious </h3>"
html += "<ul>"
for i in range(0,postlist.length):
post = postlist.item(i)
html += "<li><a href='"+unicode(post.attributes['href'].value)+"' "
html += "title='"+unicode(post.attributes['description'].value)+"'>"
html += unicode(post.attributes['description'].value)+"</a></li>"
html += "</ul>"
print html
The above code prints an html list containing my recent bookmarks in delicious.
I think it is fairly simple to understand the above code.
Similar links from my delicious
Comments
On April 4, 2010,
geo said:
EEE
Post a comment
On April 4, 2010, geo said:
EEE

On April 4, 2010, geo said:
thanks