emacs-blogger /

from blogger import Blogger
from Pymacs import lisp,Let
import os
import filters
import picasa
interactions = {}

class LispInteractive(object):
    def __init__(self):
        self.authenticated = False

    def authenticate(self):
        '''Authenticate the user and return True if succeed else False
        username = lisp["blogger-username"].value()
        password = lisp["blogger-password"].value()
            self.blogger = Blogger(username, password)
            self.authenticated = True
            return False
        return True
    def refresh(self):
        '''refresh the cached list of blogs and entries
        self.blogs = list(self.blogger.get_blogs())

    def blog(self):
        if hasattr(self,"_blog"):
            return self._blog
            lisp.error("Current Blog not selected")
    def set_blog(self, blog_id):
        self._blog = self.get_blog(blog_id)


    def get_blogs(self):
        return [[,] for blog in self.blogs]    
    def get_blog_id(self,name):
        '''get a blog by name
            return next( for blog in self.blogs if == name)
        except StopIteration:
            lisp.error("Blog name '%s' not correct"%name)
    def get_entries(self):
        '''get entries of the current blog selected (attr .blog)
        blog =
        entries = blog.get_entries()
        return [[ ,entry.title, entry.updated.strftime("%d/%m/%Y"), entry.category] \
                    for entry in entries]
    def get_blog_names(self):
        '''return a list of the blog names
        return [ for bl in self.blogs]

    def get_blog(self, blog_id):
        return next(blog for blog in self.blogs if == blog_id)
    def get_a_blog(self,blog_id=None):
        blog = self.blogs[0] if blog_id == None else self.get_blog(blog_id)
        return blog

    def post(self, title, content):
        '''Post this article to the current blog,
        return the article id
        entry =, content)
    def update_post(self, post_id, title=None, content=None):
        blog =
        blog.update_post(post_id, title, content)
    def delete_post(self, post_id, blog_id = None):
        blog =

    def upload_image(self, filename):
        c = picasa.Client()
        username = lisp["blogger-username"].value()
        password = lisp["blogger-password"].value()
        c.login(username, password)
        return c.add_photo(os.path.expanduser(filename))
    def tag_post(self, post_id, tags):
        blog =
        blog.add_tags(str(post_id), tags)
li = LispInteractive()

# Exposing functions
authenticate = li.authenticate
refresh = li.refresh

get_entries = li.get_entries
get_blog_names = li.get_blog_names
get_blog_id = li.get_blog_id
set_current_blog_by_name = lambda name: li.set_blog(li.get_blog_id(name))

post =
rst2blogger = filters.pipe(filters.rst2html,
delete_post = li.delete_post
update_post = li.update_post
tag_post = li.tag_post

upload_image = li.upload_image

# Interactive functions
interactions = {}
interactions[upload_image] = "fSelect image to upload: "

# Local Variables:
# pymacs-auto-reload: t
# End: