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)
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 getSearchFeed(self, requestData): """ get the feed @param requestData: list of requestData @type requestData: RequestData @rtype: String @return feed as xml """ path = requestData.unquotedPath[9:] query = requestData.value("query") entries = [] if query != None: results = self.rep.search(query) if len(results) > 0: for id in results: entry = self.__getEntryForDocument(path, id) if entry != None: entries.append(entry) queryStr = "/?" for key in requestData.keys(): val = requestData.value(key) if not key in ["func", "format"]: queryStr += "%s=%s&" % (key, val) altUrl = "http://%s:%s%s" % (self.hostname, self.iceWebPort, queryStr[:-1]) self.feed.id = atom.Id(text=self.__getAtomTagId(query)) self.feed.updated = atom.Updated(text=datetime.now().isoformat() + 'Z') self.feed.link = [ atom.Link(href="%s&format=atom" % altUrl, rel="self"), atom.Link(href=altUrl, rel="alternate") ] self.feed.author = [atom.Author(name=atom.Name(text="ICE"))] self.feed.entry = entries feedXml = self.feed.ToString() #remove the namespace generated by elementtree/gdata as it causes #problems with some readers feedXml = feedXml.replace(":ns0", "") feedXml = feedXml.replace("ns0:", "") #insert the title manually as elementtree/gdata places the title in the #wrong position insertPos = feedXml.find("<entry>") feedXml = "%s<title>%s - %s</title>%s" % ( feedXml[0:insertPos], self.title, query, feedXml[insertPos:]) return feedXml
def setUp(self): self.updated = atom.Updated()