コード例 #1
0
def do_obtain_new_books(cpus, account, notification=lambda x, y:x):
    print "do_obtain_new_books in jobs.py"

    print "Account is: %s" % (account)

    # This server is an arbitrary_n job, so there is a notifier available.
    # Set the % complete to a small number to avoid the 'unavailable' indicator
    notification(0.01, "Starting up...")

    from calibre.library import db
    from calibre.utils.config import prefs
    prefs.refresh()
    db = db(read_only=False)

    print "DB is: %s" % (db)

    prefs = PrefsFacade(db)
    print "Prefs are: %s" % (prefs)
    print "Library id is (%s)" % (prefs.get_library_uuid())

    reporter = ConsoleReporter()
    downloader = BeamEbooksDownloader(prefs, caller = reporter)
    print "-- LALA -- Downloader is: %s" % (downloader)

    if account[prefs.ENABLED]:
        downloader.login(account)

        if downloader.successful_login == False:
            notification(1.00, "Failed to log in...")
        else:
            notification(0.05, "Parsing document tree now...")
            downloadable_ebooks = downloader.recursive_descent(norms(prefs[prefs.URLBASE]))
            notification(0.50, "Loaded OPDS pages")
            reporter.notify(downloadable_ebooks)
            #
            # Now, download the obtained ebooks...

    notification(1.00, "Done...")

    adder = EBookAdder(prefs, "beam-ebooks")

    adder.load_books()

    new_ebooks = []

    for entry in downloadable_ebooks:
        beamebooks_id = entry['id']

        book = adder.books_of_this_shop.get(beamebooks_id)
        if book is None:
            new_ebooks.append(entry)

    result = (new_ebooks)

    return result
コード例 #2
0
    def download_ebooks(self):

        print "Library id is (%s)" % (self.prefs.get_library_uuid())

        db = self.prefs._get_db()
        print "Library database object is (%s)" % (db)

        caller = self.caller

        self.adder = EBookAdder(self.prefs, "beam-ebooks")

        self.adder.load_books()

        handled_ebooks = 0
        for entry in self.downloadable_ebooks:

            beamebooks_id = entry['id']

            book = self.adder.books_of_this_shop.get(beamebooks_id)
            if book is None:
                # Book not found, fetch and try to store in into the database
                if handled_ebooks < self.prefs[
                        self.prefs.DOWNLOADS_PER_SESSION]:
                    handled_ebooks = handled_ebooks + 1
                    # Still in quota for this run
                    if caller is not None:
                        caller.notify("Working on book %d: %s" %
                                      (handled_ebooks, beamebooks_id))

                    self.download_ebook(entry)

                else:
                    continue

        if caller is not None:
            caller.notify("Handled (%d of %d) books, waiting for next run" %
                          (handled_ebooks, len(self.downloadable_ebooks)))