示例#1
0
 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()
     ])
示例#2
0
文件: utils.py 项目: guaka/gutenberg
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]
示例#3
0
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]
示例#4
0
 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()])
示例#5
0
文件: urls.py 项目: emijrp/gutenberg
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)
示例#6
0
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)