예제 #1
0
def main():
    from book.models import Book, Author


    books = Book.objects.all()

    was_last_book = False
    for book in books:
        if EpubBook.objects.filter(book=book):
            continue
        http = book.book_file.get_query_set()[0].link + "_with-big-pictures.html"
        http = string.replace(http, "koi/", "")
        #if not was_last_book and last_book == http + "\n":
        #    was_last_book = True

        #if not was_last_book:
        #    break
        name = book.title
        language = book.language
        authors = {}
        author_name = ""
        genres = []
        for i, author in enumerate(book.author.get_query_set()):
            if i == 0:
                author_name = author.name
            else:
                authors.append(author.name)
        for tag in book.tag.get_query_set():
            genres.append(tag.name)

        temp_name = 'temp'
        properties = BookProperties("books/" + temp_name, name)
        properties.language = language
        properties.author = author_name
        properties.authors = authors
        properties.genre = ", ".join(genres)
        lrp = LibRuParser(http, properties)

        lrp.parse()
        if not lrp.create_book():
            print "Error in creating book."
            continue

        ebook = EpubBook.objects.create()
        ebook.name.save(name + ".epub", _ExistingFile("books/" + temp_name + ".epub"))
        ebook.book = book
        ebook.save()

        last_book = http
예제 #2
0
def get_book(link):
    http = link + "_with-big-pictures.html"
    http = string.replace(http, "koi/", "")
    name="temp"
    language = "ru"
    authors = {}
    author_name = ""
    genres = []
    temp_name = 'temp.epub'
    properties = BookProperties("books/" + temp_name, name)
    properties.language = language
    properties.author = author_name
    properties.authors = authors
    properties.genre = ", ".join(genres)
    lrp = LibRuParser(http, properties)

    lrp.parse()
    if not lrp.create_book():
        print "Error in creating book."