コード例 #1
0
    def __post(self, author, title, summary, content, category, draft,
               entryXml):
        """ to post the content to the server
        @param author: Author name
        @type author: String
        @param title: Title of the content
        @type title: String
        @param summary: Summary of the content
        @type summary: String
        @param content: Content 
        @type content: String
        @param draft: Type of the document:
        @type draft: boolean
        @param entryXml: extra entry
        @type entryXml: String
        
        @rtype: (Atom Entry, String)
        @return: entry, httpResponse
        """
        # create/update the atom entry
        if entryXml == None:
            entry = atom.Entry()
            entryUri = self.entryUri

        else:
            entry = atom.EntryFromString(entryXml)
            entryUri = entry.GetEditLink().href
        entry.author = [atom.Author(text=author)]
        entry.title = atom.Title(text=title)
        entry.summary = atom.Summary(text=summary)
        entry.content = atom.Content(content_type="html",
                                     text=unicode(content, "utf-8"))
        if category != "":
            entry.category = atom.Category(term=category)
        if draft:
            entry.control = atom.Control(draft=atom.Draft(text="yes"))
        else:
            entry.control = atom.Control(draft=atom.Draft(text="no"))
        # setup the http headers for authorisation
        extraHeaders = {"Slug": title}
        extraHeaders.update(self.authHeaders)
        # use POST or PUT depending on whether it is a new entry or an update
        if entryXml != None:
            publishFunc = self.atomService.Put
        else:
            publishFunc = self.atomService.Post
        self.__checkNoProxy(entryUri)
        httpResponse = publishFunc(data=entry,
                                   uri=entryUri,
                                   extra_headers=extraHeaders)
        self.__resetProxy()
        return entry, httpResponse
コード例 #2
0
    def CreatePost(self, title, content, author_name, tags, 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)
        for tag in tags:
            category = atom.Category(term=tag,
                                     scheme="http://www.blogger.com/atom/ns#")
            entry.category.append(category)

        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')
コード例 #3
0
    def testPostDraftUpdateAndDelete(self):
        new_entry = gdata.blogger.BlogPostEntry(title=atom.Title(
            text='Unit Test Post'))
        new_entry.content = atom.Content('text', None, 'Hello World')
        # Make this post a draft so it will not appear publicly on the blog.
        new_entry.control = atom.Control(draft=atom.Draft(text='yes'))
        new_entry.AddLabel('test')

        posted = self.client.AddPost(new_entry, blog_id=test_blog_id)

        self.assertEqual(posted.title.text, new_entry.title.text)
        # Should be one category in the posted entry for the 'test' label.
        self.assertEqual(len(posted.category), 1)
        self.assertTrue(isinstance(posted, gdata.blogger.BlogPostEntry))

        # Change the title and add more labels.
        posted.title.text = 'Updated'
        posted.AddLabel('second')
        updated = self.client.UpdatePost(entry=posted)

        self.assertEqual(updated.title.text, 'Updated')
        self.assertEqual(len(updated.category), 2)

        # Cleanup and delete the draft blog post.
        self.client.DeletePost(entry=posted)
コード例 #4
0
    def createPost(self,
                   title,
                   content,
                   authorName,
                   labels=None,
                   isDraft=False):

        # Create a gdata entry.
        entry = gdata.GDataEntry()
        # append author.
        entry.author.append(atom.Author(atom.Name(text=authorName)))
        entry.title = atom.Title(title_type='xhtml', text=title)

        # handle labels by using atom.Category.
        if labels:
            for label in labels:
                category = atom.Category(scheme=blogger.LABEL_SCHEME,
                                         term=label)
                entry.category.append(category)

        # handle draft,
        if isDraft:
            control = atom.Control()
            control.draft = atom.Draft(text='yes')
            entry.control = control

        # add content.
        entry.content = atom.Content(content_type='html', text=content)

        return self.gdService.Post(entry, self.postsUri)
コード例 #5
0
ファイル: bloggeratom.py プロジェクト: Ryuno-Ki/BloGTK3
    def createPost(self,
                   blogID,
                   title,
                   content,
                   author_name,
                   is_draft,
                   timestamp=None):
        """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='Post author')))
        entry.title = atom.Title('xhtml', text=title)
        entry.content = atom.Content('html', text=content)
        if is_draft:
            control = atom.Control()
            control.draft = atom.Draft(text='yes')
            entry.control = control

        # If a timestamp is specified, use that timestamp
        if timestamp:
            entry.published = atom.Published(timestamp)

        # Ask the service to insert the new entry.
        return self.service.Post(entry, '/feeds/' + blogID + '/posts/default')
コード例 #6
0
ファイル: bloggeratom.py プロジェクト: Ryuno-Ki/BloGTK3
    def editPost(self,
                 blogID,
                 postID,
                 title,
                 content,
                 author_name,
                 is_draft,
                 timestamp=None):

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

        # If a timestamp is specified, use that timestamp
        if timestamp:
            entry.published = atom.Published(timestamp)

        # Ask the service to insert the new entry.
        return self.service.Put(
            entry, '/feeds/' + blogID + '/posts/default/' + postID)
コード例 #7
0
ファイル: service.py プロジェクト: amitkr/googlecl-vinitkumar
    def _upload_content(self,
                        post_title,
                        content,
                        blog_id=None,
                        is_draft=False):
        """Uploads content.

        Keyword arguments:
          blog_title: Title of the blog to post to.
          title: Title to give the post.
          content: String to get posted. This may be contents from a file, but NOT
                   the path itself!
          is_draft: If this content is a draft post or not. (Default False)

        Returns:
          Entry of post. (Returns same results as self.AddPost())
        """
        entry = gdata.blogger.BlogPostEntry()
        entry.title = atom.Title(title_type='xhtml', text=post_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
        return self.AddPost(entry, blog_id)
コード例 #8
0
ファイル: blogger.py プロジェクト: sermmor/Blogodt
def create_entry(title, content, draft=False):
    import gdata
    entry = update_entry(gdata.GDataEntry(), title, content)
    if draft:
        control = atom.Control()
        control.draft = atom.Draft(text='yes')
        entry.control = control
    return entry
コード例 #9
0
 def testConvertToAndFromString(self):
     draft = atom.Draft()
     draft.text = 'maybe'
     draft.extension_attributes['foo'] = 'bar'
     self.assertEquals(draft.text, 'maybe')
     self.assertEquals(draft.extension_attributes['foo'], 'bar')
     new_draft = atom.DraftFromString(str(draft))
     self.assertEquals(draft.text, new_draft.text)
     self.assertEquals(draft.extension_attributes['foo'],
                       new_draft.extension_attributes['foo'])
コード例 #10
0
 def testConvertToAndFromString(self):
     control = atom.Control()
     control.text = 'some text'
     control.draft = atom.Draft(text='yes')
     self.assertEquals(control.draft.text, 'yes')
     self.assertEquals(control.text, 'some text')
     self.assertEquals(isinstance(control.draft, atom.Draft), True)
     new_control = atom.ControlFromString(str(control))
     self.assertEquals(control.draft.text, new_control.draft.text)
     self.assertEquals(control.text, new_control.text)
     self.assertEquals(isinstance(new_control.draft, atom.Draft), True)
コード例 #11
0
ファイル: webutil.py プロジェクト: seanchen/plonexp
    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.
        """

        # Authenticate using ClientLogin.
        self.service = service.GDataService('user', '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]

        # 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')