Fetch Blogger latest posts with Python, Django, Urllib and XML

http://code.google.com/apis/blogger/docs/2.0/developers_guide_protocol.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from urllib2 import *
from xml.dom import minidom

def get_latest_post():
    POST_ID = '7866159460691223515'
    url = 'http://www.blogger.com/feeds/%s/posts/default?max-results=1' % POST_ID

    try:
        hndl = urllib2.urlopen(url,None)
    except urllib2.HTTPError, ex:
        raise ex

    resp = hndl.read()

    doc = minidom.parseString(resp)
    if doc.hasChildNodes():
        node = doc.getElementsByTagName("entry")
        arr = []
        for r in node:
            node_info = {}
            for n in r.childNodes:
                print n.nodeName
                try: node_info[n.nodeName] = n.firstChild.nodeValue
                except: pass
            arr.append(node_info)
        return arr

Comments

Comments are closed.