def update( file_name, interactive=False ): '''update( file_name, interactive=False ) Formats and updates a post in a restblog from the given `file_name`. Parameters: - file_name Input file name with a post written in reStructuredText. - interactive Prompts for missing credentials if set to True. False by default. ''' try: html_file_name = post.createFormattedPost( file_name ) metadata, contents = post.getPostContents( html_file_name ) id = int( metadata.attrib[ 'id' ] ) publish = metadata.attrib.get( 'publish', 'yes' ) == 'yes' blog = server.connect( interactive=interactive ) if metadata.attrib[ 'type' ] == 'page': success = blog.editPage( id, contents, publish=publish ) else: success = blog.editPost( id, contents, publish=publish ) if not success: raise RuntimeError, 'Unexpected error when updating post' except Exception, ex: print 'Unable to update restblog post from file %(file_name)s. Error: %(ex)s' % locals()
def insert( file_name, interactive=False ): '''insert( file_name, interactive=False ) Formats and inserts a new post in a restblog from the given `file_name`. Parameters: - file_name Input file name with a post written in reStructuredText. - interactive Prompts for missing credentials if set to True. False by default. ''' try: html_file_name = post.createFormattedPost( file_name ) metadata, contents = post.getPostContents( html_file_name ) publish = metadata.attrib.get( 'publish', 'yes' ) == 'yes' blog = server.connect( interactive=interactive ) if metadata.attrib[ 'type' ] == 'page': id = blog.newPage( contents, publish=publish ) else: id = blog.newPost( contents, publish=publish ) metadata.attrib[ 'id' ] = id post.updateSourceMetadata( file_name, metadata ) except Exception, ex: print 'Unable to insert post into restblog from file %(file_name)s. Error: %(ex)s' % locals()