def AddPhoto(filename, summary, title, imageFormat='jpeg', timestamp=None):
    if isImageFile(filename) == False:
        log('Not Image: %s', filename)
        OTHER_FILES.append(filename)
        return
    log('Uploading photo: %s', filename)
    url = '/data/feed/api/user/%s/albumid/%s?kind=photo' % (USERNAME, ALBUM_ID)
    metadata = gdata.photos.PhotoEntry()
    metadata.title = atom.Title(text=title)
    metadata.summary = atom.Summary(text=summary, summary_type='text')
    if UPDATE_FILE_METADATA == True and timestamp is not None:
        metadata.timestamp = gdata.photos.Timestamp(text=timestamp)
        metadata.published = atom.Published(
            text=metadata.timestamp.isoformat())
        metadata.updated = atom.Updated(text=metadata.timestamp.isoformat())
        UpdateFileMetadata(filename, metadata.timestamp.datetime())

    if DRY_RUN == False:
        try:
            photo = gd_client.InsertPhoto( \
                url, metadata, filename, 'image/' + imageFormat)
            if photo is None:
                ERRORS.append('Photo may not have been uploaded: ' + filename)
        except gdata.photos.service.GooglePhotosException:
            ERRORS.append('Photo may not have been uploaded: ' + filename)
Beispiel #2
0
    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)
Beispiel #3
0
    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')
    def __getEntryForDocument(self, queryPath, id):
        """  
        @param queryPath: Query to search for the entry
        @type queryPath: String
        @param id: Id to be applied to atom feed
        @type id: String
        @rtype: ElementTree._Element, or xml_wrapper.ElementWrapper
        @return entry
        """
        docPath = self.rep.getPathForId(id)
        # check docPath
        if docPath.startswith(queryPath):
            item = self.rep.getItem(docPath)
            if item.hasHtml:
                docPath = self.iceContext.fs.splitExt(docPath)[0] + ".htm"
            title = item.getMeta("title")
            try:
                title = title.decode("utf-8")
            except:
                msg = "[Can not display title because of an encoding error!]"
                print "%s\n title='%s' path='%s'\n" % (msg, title, docPath)
                title = msg
            content = item.getRendition(".xhtml.body")
            if content is None:
                content = "<p>[Not rendered!]</p>"
            contentElem = ElementTree.XML(content)
            firstPara = contentElem.find("p")
            summary = "No summary"
            if firstPara != None:
                summary = ElementTree.tostring(firstPara)

            name = item.name
            lastModifiedTime = self.iceContext.fs.getModifiedTime(
                self.rep.getAbsPath(name))
            entryDate = datetime.fromtimestamp(
                lastModifiedTime).isoformat() + 'Z'
            srcUrl = "http://%s:%s%s" % (self.hostname, self.iceWebPort,
                                         docPath)

            entry = atom.Entry(title=atom.Title(text=title))
            entry.id = atom.Id(text="urn:uid:%s" % id)
            entry.link = [atom.Link(href=srcUrl, rel="alternate")]
            entry.updated = atom.Updated(text=entryDate)
            entry.published = atom.Published(text=entryDate)
            entry.summary = atom.Summary(summary_type="html",
                                         text=unicode(summary, "utf-8"))
            entry.content = atom.Content(content_type="html",
                                         text=unicode(content, "utf-8"))
            return entry
        else:
            return None
 def setUp(self):
     self.published = atom.Published()