try:
from xml.etree import ElementTree # for Python 2.5 users
except:
from elementtree import ElementTree
from gdata import service
import gdata
import atom
import getopt
import sys
class Blogger:
def __init__(self,email,password):
self.email = email
self.password = password
self.service = None
try:
from xml.etree import ElementTree # for Python 2.5 users
except:
from elementtree import ElementTree
from gdata import service
import gdata
import atom
import getopt
import sys
class Blogger:
def __init__(self,email,password):
self.email = email
self.password = password
self.service = None
def connect(self):
self.service = service.GDataService(self.email, self.password)
self.service.source = 'Donghua Blogger Script'
self.service.service = 'blogger'
self.service.server = 'www.blogger.com'
self.service.ProgrammaticLogin()
self.blog_id = ""
feed = self.service.Get('/feeds/default/blogs')
for a_link in feed.entry[0].link:
if a_link.rel == 'self':
self.blog_id = a_link.href.split("/")[-1]
def create_post(self,title,content):
# Create the entry to insert.
entry = gdata.GDataEntry()
#entry.author.append(atom.Author(atom.Name(text=author_name)))
entry.title = atom.Title('xhtml', title)
entry.content = atom.Content('html', '', content)
# Ask the service to insert the new entry.
return self.service.Post(entry,
'/feeds/' + self.blog_id + '/posts/default')
if __name__ == "__main__":
email = "**********"
password = "*********"
myblogger = Blogger(email,password)
myblogger.connect()
aa = myblogger.create_post("test title","test content2222")
print aa