micro blogging from nokia tablets

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 1/8/08, Daniel Martin Yerga <dyerga at gmail.com> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Mon, 7 Jan 2008 22:26:26 -0800
> "Jayesh Salvi" <jayesh at altfrequency.com> wrote:
>
> > Thanks. maemo-wordpy looks like a great software. Maybe I should make
> > a patch for it to add blogger.com backend.
>
> Thanks.
>
> I had thought to add support for other blogging systems, among them
> blogger.com, in future versions. But if you can do a patch for blogger
> it will be welcome, of course.
>
> In the SVN is the most updated version it still has some bugs. It
> has only few comments, so if you have some question you don't
> hesitate to do it.


Hey Daniel,

I looked at the maemo-wordpy source code.  It is pretty big for me to go
through and patch. Comparatively the blogger.com specific code is extremely
tiny.

In fact I will paste in this email the source code that will get it working.
It is so small, because the GData library is packaged separately. I have
created the .deb installable for it and you can find it
here<http://www.altcanvas.com/packages/gdata-python_1.0.10.1.deb>

Assuming that above library is installed all you need is following class
definition:

try:
  from xml.etree import ElementTree # for Python 2.5 users
except:
  from elementtree import ElementTree

from gdata import service
import gdata
import atom

class Blogger:

  def __init__(self, email, password):
    """Creates a GDataService and provides ClientLogin auth details to it.
    The email and password are required arguments for ClientLogin.  The
    'source' defined below is an arbitrary string, but should be used to
    reference your name or the name of your organization, the app name and
    version, with '-' between each of the three values."""

    # Authenticate using ClientLogin.
    self.service = service.GDataService(email, password)
    self.service.source = 'Blogger_Python_Sample-1.0'
    self.service.service = 'blogger'
    self.service.server = 'www.blogger.com'
    self.service.ProgrammaticLogin()

    # Get the blog ID for the first blog.
    feed = self.service.Get('/feeds/default/blogs')
    self_link = feed.entry[0].GetSelfLink()
    if self_link:
      self.blog_id = self_link.href.split('/')[-1]

  def CreatePost(self, title, content, author_name, is_draft):
    """This method creates a new post on a blog.  The new post can be stored
as
    a draft or published based on the value of the is_draft parameter.  The
    method creates an GDataEntry for the new post using the title, content,
    author_name and is_draft parameters.  With is_draft, True saves the post
as
    a draft, while False publishes the post.  Then it uses the given
    GDataService to insert the new post.  If the insertion is successful,
the
    added post (GDataEntry) will be returned.
    """

    # Create the entry to insert.
    entry = gdata.GDataEntry()
    entry.author.append(atom.Author(atom.Name(text=author_name)))
    entry.title = atom.Title(title_type='xhtml', text=title)
    entry.content = atom.Content(content_type='html', text=content)
    if is_draft:
      control = atom.Control()
      control.draft = atom.Draft(text='yes')
      entry.control = control

    # Ask the service to insert the new entry.
    return self.service.Post(entry,
      '/feeds/' + self.blog_id + '/posts/default')

if __name__ == '__main__':
        blogger = Blogger(username,password)
        content = 'Here goes the blog's content'
        title = 'Title'
        post = blogger.CreatePost(title,content,username,is_draft=False)

        if post:
            print  post.title.text

=====================

The above example will just post on blog. If you want to do other things
like list all posts, comments, etc., then you can take a look at this
file<http://gdata-python-client.googlecode.com/svn/trunk/samples/blogger/BloggerExample.py>

Hope that helps. Let me know if you need any other help.

Jayesh


The SVN version needs flickrapi, for some flickr options, but
> commenting these lines it can work without flickrapi (except the flickr
> part).
> Also in chinook it needs python-gtkhtml that it's in the garage
> (https://garage.maemo.org/projects/python-gtkhtml2/) or in the
> extras-devel repository.
>
> Best Regards.
> - --
> Daniel Martin Yerga
> http://yerga.net
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFHg59PcnvB1T3xmfMRAlwNAJ4hXzjLhPiOgEnJ0z2dfuKCjNgR/QCfQPfs
> DJ1Jr0mZamtocCJnjRDZ1yo=
> =6n8l
> -----END PGP SIGNATURE-----
>



-- 
---
Jayesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maemo.org/pipermail/maemo-users/attachments/20080108/0c4a525e/attachment.htm 


[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Big List of Linux Books]    

  Powered by Linux