def main_formats_for(book): fmts = [fmt.format.mime for fmt in BookFormat.select(BookFormat, Book, Format) .join(Book).switch(BookFormat) .join(Format) .where(Book.id == book.id)] return [k for k, v in FORMAT_MATRIX.items() if v in fmts]
def main_formats_for(book): fmts = [ fmt.format.mime for fmt in BookFormat.select(BookFormat, Book, Format).join( Book).switch(BookFormat).join(Format).where(Book.id == book.id) ] return [k for k, v in FORMAT_MATRIX.items() if v in fmts]
def nb_by_fmt(fmt): return sum([ 1 for book in books if BookFormat.select(BookFormat, Book, Format).join(Book).switch( BookFormat).join(Format).where(Book.id == book.id).where( Format.mime == FORMAT_MATRIX.get(fmt)).count() ])
def nb_by_fmt(fmt): return sum([1 for book in books if BookFormat.select(BookFormat, Book, Format) .join(Book).switch(BookFormat) .join(Format) .where(Book.id == book.id) .where(Format.mime == FORMAT_MATRIX.get(fmt)) .count()])
def get_urls(book): """ Get all possible urls that could point to the book on either of the two mirrors. param: book: The book you want the possible urls from returns: a list of all possible urls sorted by their probability """ filtered_book = [bf.format for bf in BookFormat.select().where(BookFormat.book == book)] # Strip out the encoding of the file f = lambda x: x.mime.split(';')[0].strip() available_formats = [ {x.pattern.format(id=book.id): {'mime': f(x), 'id': book.id}} for x in filtered_book if f(x) in FORMAT_MATRIX.values()] files = sort_by_mime_type(available_formats) return build_urls(files)
def get_urls(book): """ Get all possible urls that could point to the book on either of the two mirrors. param: book: The book you want the possible urls from returns: a list of all possible urls sorted by their probability """ filtered_book = [ bf.format for bf in BookFormat.select().where(BookFormat.book == book) ] # Strip out the encoding of the file f = lambda x: x.mime.split(';')[0].strip() available_formats = [{ x.pattern.format(id=book.id): { 'mime': f(x), 'id': book.id } } for x in filtered_book if f(x) in FORMAT_MATRIX.values()] files = sort_by_mime_type(available_formats) return build_urls(files)