def _loadfromcache(self, xmlnode, dir): """Load the OpacBookItem from cache Argument xmlnode -- XML node describing this item """ BookItem._loadfromcache(self, xmlnode, dir) self.author = xmlnode.attributes[attr_author].value
def cleanup(self): """Clean up data associated with this item.""" if(self._video != ''): try: os.remove(self._video) except OSError: print('Could not delete ' + self._video) BookItem.cleanup(self)
def _loadfromcache(self, xmlnode, dir): """Load the BlogspotItem from cache Argument xmlnode -- XML node describing this item """ BookItem._loadfromcache(self, xmlnode, dir) if((xmlnode.attributes[attr_video] is not None) and (xmlnode.attributes[attr_video].value != '')): self._video = os.path.join(dir, xmlnode.attributes[attr_video].value) else: self._video = ''
def getXml(self, doc, name): """"Return an XML representation of this BlogspotItem. Arguments doc -- the XML doc in which to create the node name -- the name of the node """ element = BookItem.getXml(self, doc, name) element.setAttribute(attr_video, os.path.basename(self._video)) return element
def getXml(self, doc, name): """"Return an XML representation of this OpacBookItem. Arguments doc -- the XML doc in which to create the node name -- the name of the node """ element = BookItem.getXml(self, doc, name) element.setAttribute(attr_author, self.author) return element
subclass BlogspotItemWithIsbn is used in the third Varberg display. """ def __init__(self, (dir, dims, smalldims, library), xmlnode = None, blogpostdata = None): """Create BlogspotItem. Arguments dir -- the cache directory dims -- tuple containing normal width and height of the image smalldims -- tuple containing small width and height of the image library -- if not None only books from this library will be considered xmlnode -- if not None the BlogspotItem will be loaded from this cache node blogpostdata -- if not None the BlogspotItem will be loaded from this BlogPostData """ BookItem.__init__(self, dims, smalldims) self._video = '' if(xmlnode is not None): self._loadfromcache(xmlnode, dir) self._loadimage(dims, smalldims) self._formattext() elif(blogpostdata is not None): self.uid = str(uuid.uuid1()) self._rawtitle = blogpostdata.title self.section = '' self.shelf = '' self.subjects = blogpostdata.subjects rawtext = blogpostdata.content self._rawtext = rawtext self._formattext()
def __init__(self, (dir, dims, smalldims, library), xmlnode=None, url=None): """Initiate the OpacBookItem. Either xmlnode xor url shall be specified. Arguments dir -- the cache directory dims -- tuple containing normal width and height of the image smalldims -- tuple containing small width and height of the image library -- if not None only books from this library will be considered xmlnode -- if not None the OpacBookItem will be loaded from this cache node url -- if not None the OpacBookItem will be loaded from this url """ BookItem.__init__(self, dims, smalldims) if (xmlnode is not None): self._loadfromcache(xmlnode, dir) self.author = xmlnode.attributes[attr_author].value self._loadimage(dims, smalldims) elif (url is not None): try: data = itemharvester.harvestBookInfo(url, library) except: self.valid = False return self._rawtitle = data.title self.author = data.author self._rawtext = data.rawtext
inputDir = sys.argv[1] outputDir = sys.argv[2] params = {'shuffle': True, 'clean': True, 'appendBookData': True, 'zipOutput': True, 'flushMetaData': True, 'expand': True, 'cleanHead': True} bulkName = datetime.datetime.now().strftime('%y%m%d') booksList = BooksList(inputDir) if params['shuffle']: booksList.shuffle() num = 1 for bookFilePath in booksList.books: bookObject = BookItem(bookFilePath) fileTitle = '%s-%04d' % (bulkName, num) if params['clean']: bookObject.clean() if params['appendBookData']: bookObject.appendBookData() if params['cleanHead']: bookObject.cleanHead() if params['flushMetaData']: bookObject.flushMetaData(fileTitle)