3 messages in com.googlegroups.bloggerdevRe: [bloggerDev] Python code example ...| From | Sent On | Attachments |
|---|---|---|
| Sandra | 21 May 2005 23:45 | |
| Mr. Charming | 22 May 2005 00:28 | |
| Law | 22 May 2005 21:05 |
| Subject: | Re: [bloggerDev] Python code example for posting blogger messages![]() |
|---|---|
| From: | Law (lawn...@texasturkey.us) |
| Date: | 05/22/2005 09:05:35 PM |
| List: | com.googlegroups.bloggerdev |
Thank you, thank you, thank you!
Sandra wrote:
I have to imagine others are having as tough a time as myself getting messages to post via blogger. Heck there's several threads with no answers looking for some code. This is the code I just cobbled together tonight (with old school comment format). It appears to work:
import httplib import base64 import time
username = "your blogger username here" password = "your blogger password here" host = "www.blogger.com"
def postMessage(title, link, message,bID=""): """ postMessage - Posts a message to a blogger blog.
Parameters: title - Title of the blog entry link - link for the blog entry (not used here) bID - the blog id for posting Uses Constants: username - your blog user name password - Your blog password host - Constant: www.blogger.com Outputs: Prints results of the https call to stdout.
Notes: The blogID is tricky to find. Here's how I do it: 1. Log into your blogger account at www.blogger.com 2. From the Dashboard, click the blog name who's ID you want 3. The url in the address bar will look like: http://www.blogger.com/posts.g?blogID=your_blog_id_here 4. your_blog_id_here is the blog id """ if bID != "": path = "/atom/%s" % (bID) # This didn't work until I added the call to strip! got a 500 error passwordDigest = base64.encodestring (username + ':' + password).strip() created = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()) # Other similar (non-Atom) examples use Basic, not BASIC so I switched basicstr = 'Basic ' + passwordDigest
headers = {"Content-type": "application/xml", "Authorization": basicstr, "Host" : host} body = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <entry xmlns="http://purl.org/atom/ns#"> <title mode="escaped" type="text/plain">"""+title+""" </title> <issued>""" + created + """</issued> <generator url="http://www.carrico.biz">Sandras generator </generator> <content type="application/xhtml+xml"> <div xmlns="http://www.w3.org/1999/xhtml">""" + message+ """</div> </content> </entry> """ try: conn = httplib.HTTPSConnection(host) conn.set_debuglevel(1) conn.request("POST", path, body, headers) response = conn.getresponse() print print response.read() conn.close() except: print "postMessage: Error posting"




