def test_book_sort(self): # create test books test_book_1 = Book(self.book_1, self.writer_1, self.isbn_1) test_book_2 = Book(self.book_2, self.writer_2, self.isbn_2) # test sorting self.assertTrue(test_book_1 < test_book_2) self.assertFalse(test_book_1 > test_book_2)
def test_book_get_info(self): # create new book test_book = Book(self.book_1, self.writer_1, self.isbn_1) # test print_info-method print_info_str = "{0}\t {1}\t {2}".format(self.book_1, self.writer_1, self.isbn_1) self.assertEqual(test_book.get_info(), print_info_str)
def test_book_creation(self): # create new book test_book = Book(self.book_1, self.writer_1, self.isbn_1) # check book values self.assertEqual(test_book.name, self.book_1) self.assertEqual(test_book.writer, self.writer_1) self.assertEqual(test_book.ISBN, self.isbn_1)
def generate_book(book: Book): print(" Generating book {}".format(book.id)) # Time to render template = env.get_template('book.html') html = template.render(book=book, media_path=media_path) with open("public/{}.html".format(book.getID()), 'w') as f: f.write(html)
def generate(): books = [] # Read the Index yaml with open('manifests/index.yaml', 'r') as f: try: index = yaml.safe_load(f) except Exception as e: print( 'Required file manifests/index.yaml missing or unreadable, ' + e) sys.exit(1) for section in index['sections']: if not options.only_index: print("Generating section {}".format(section['name'])) for i, book in enumerate(section['books']): # Check book ID is allowed if book['id'] in banned_book_ids: print("Book ID '{}' is not an allowed ID".format(book['id'])) sys.exit(1) # Generate each book try: b = Book(book['id'], book['source_dir']) except Exception as e: print("ERROR: Could not load {}; {}".format(book['id'], e)) sys.exit(1) if not options.only_index: generate_book(b) if not options.skip_media: b.export() # Generate media (cover + mp3) section['books'][i] = b # Render index print("Generating index for {} books".format( sum([len(x['books']) for x in index['sections']]))) template = env.get_template('index.html') html = template.render(index=index, media_path=media_path, extension='.html' if options.with_extension else '') with open("public/index.html", 'w') as f: f.write(html) return
def start(self): # add download folder self.__make_dir(self.config["download_path"]) # start download # book_list = [ # {'name': '進擊的巨人', 'id': 10184, 'authors': ['諫山創'], 'last_update': '2021-01-24', 'is_finished': False} # ] # for book in book_list: for book in self.book_list: # add book name folder book_details = Book(book["id"]).fetch() if self.__gen_queue(book_details) is True: self.__make_dir(self.config["download_path"] + "/" + book["name"]) for item in self.download_queue: if self.__calc_limit(item) is False: with open(os.path.join(item["file_path"], item["file_tmp"]), "wb") as f: response = requests.get(item["download_link"], stream=True, allow_redirects=True, cookies=self.config["account"], headers = { "user-agent": self.config["ua"], "refer": "https://vol.moe/c/{}.htm".format(book["id"]) }) if response.status_code != 200: print(response.text) print("Please first try downloading a book in the browser, then update the cookies in config.yml") return total = response.headers.get("content-length") self.downloading = item print("Start Downloading:", item["file"]) if total is None: f.write(response.content) else: downloaded = 0 total = int(total) for data in response.iter_content(chunk_size=max(int(total/1000), 1024*1024)): downloaded += len(data) f.write(data) done = int(50*downloaded/total) sys.stdout.write("\r[{}{}] {}/{}".format("█" * done, "." * (50-done), downloaded, total)) sys.stdout.flush() sys.stdout.write("\n") self.__rename_file(os.path.join(item["file_path"], item["file_tmp"]), os.path.join(item["file_path"], item["file"])) self.__history.add(item["book_name"], item["vol_name"]) print("Successfully downloaded:", item["file"]) self.account["left"] -= item["download_size"] self.account["used"] += item["download_size"] self.account["daily_used"] += item["download_size"] else: print("Bandwidth limit excessed") return self.download_queue = [] self.__history.finished(book)
def init_objet(): # joueur gl.playerOPY = [0,0,0,0] gl.playerOBL = [0,0,0,0] gl.ombreOBL = [0,0,0,0] gl.handOBL = [0,0,0,0] for i in range(4): # Je définis les objets python représentants les joueurs gl.playerOPY[i] = Player(i) # Je définis la liste des objets joueurs, ombre et hand dans blender (a, b, c) = gl.playerOPY[i].get_playerOPY() gl.playerOBL[i], gl.ombreOBL[i], gl.handOBL[i] = (a, b, c) # livre gl.bookOPY = [0,0,0,0] # Les livres d'un joueur est une liste de 3 gl.bookOBL = [[0,0,0],[0,0,0],[0,0,0],[0,0,0]] gl.bookSimOBL = [0,0,0,0] for i in range(4): # Je définis les objets python représentants les livres gl.bookOPY[i] = Book(i) # Je définis la liste des objets livre dans blender, # les 3 livres du joueur et le livre de simulation gl.bookOBL[i], gl.bookSimOBL[i] = gl.bookOPY[i].get_bookOPY()
signing = False for i in range(numOfLibs): libBooks = list() library = file.pop(0) currBook = file.pop(0) for n in currBook: if int(n) in books: books[int(n)] = books[int(n)] + 1 else: books[int(n)] = 1 for n in books: print(n) libBooks.append(Book(n, scores[n], books[n])) libs.append(Library(i, int(library[1]), int(library[2]), libBooks)) libs.sort(key=Library.hscore, reverse=True) signedLibs = list() signedBooks = dict() for day in range(days): if len(libs) > 0: library = libs[0] if not library.signup(day): signedLibs.append(libs.pop(0))
def add_book(self, book, writer, isbn): self.books.append(Book(book, writer, isbn))
mod = __import__(package, fromlist=[class_name]) else: mod = __import__('lib.callbacks', fromlist=['Callbacks']) class_name = 'Callbacks' return getattr(mod, class_name) if __name__ == '__main__': (options, args) = parse_options() setup_logger(options.debug) config = Config(options.config, options.debug, options.toc_break) logging.getLogger().info(str(config)) if options.clear and os.path.exists(config.cache): shutil.rmtree(config.cache) os.makedirs(config.cache, exist_ok=True) klass = get_callback_class(config.callbacks) book = Book(config, klass(config)) book.load_html() try: epub.write_epub(config.book.epub_filename, book.generate_epub(), {}) except Exception as e: print(traceback.format_exc())
class_name = callback_config_str.split('.')[-1] mod = __import__(package, fromlist=[class_name]) else: mod = __import__('lib.callbacks', fromlist=['Callbacks']) class_name = 'Callbacks' return getattr(mod, class_name) if __name__ == '__main__': (options, args) = parse_options() setup_logger(options.debug) config = Config(options.config, options.debug, options.toc_break) logging.getLogger().info(str(config)) if options.clear and os.path.exists(config.cache): shutil.rmtree(config.cache) os.makedirs(config.cache, exist_ok=True) klass = get_callback_class(config.callbacks) book = Book(config, klass(config)) book.load_html() try: epub.write_epub(config.book.epub_filename, book.generate_epub(), {}) except Exception as e: print(traceback.format_exc())