Example #1
0
    def rent_book(self, book: Book) -> bool:
        """ Rents this book

        :param book: The book to be rented
        :return: True iff the book was successfully rented. False otherwise
        """

        if not book.is_rented and book not in self.rented_books and \
                book.owned_by in self.libraries:

            book.due_date = date.today() + timedelta(days=7)
            book.is_rented = True
            book.rent_list.enqueue(self)
            # Add the member to the front of the queue to signify that they
            # are renting the book

            self.rented_books.append(book)

            return True

        elif book.is_rented:
            print(
                "The book is currently being rented and you will be placed on"
                "the wait list.")

            book.rent_list.enqueue(self)
            return True

        return False
Example #2
0
def viewpublications():
    publications = root.child('publications').get()
    list = []  #create a list to store all the publication objects
    print(publications)
    for pubid in publications:

        eachpublication = publications[pubid]

        if eachpublication['type'] == 'smag':
            magazine = Magazine(
                eachpublication['title'], eachpublication['publisher'],
                eachpublication['status'], eachpublication['created_by'],
                eachpublication['category'], eachpublication['type'],
                eachpublication['frequency'])
            magazine.set_pubid(pubid)
            print(magazine.get_pubid())
            list.append(magazine)
        else:
            book = Book(eachpublication['title'], eachpublication['publisher'],
                        eachpublication['status'],
                        eachpublication['created_by'],
                        eachpublication['category'], eachpublication['type'],
                        eachpublication['synopsis'], eachpublication['author'],
                        eachpublication['isbn'])
            book.set_pubid(pubid)
            list.append(book)

    return render_template('view_all_publications.html', publications=list)
Example #3
0
 def test_short_updatbook(self): #make certain that the library updates books properly
     book = Book(textfile='invalidfile.txt')
     library = Library.Library()
     book.statusmsg = False
     library.add_book(book)
     self.assertFalse(library.get_book_uid(book.id).statusmsg)
     book.statusmsg = True
     self.assertTrue(library.get_book_uid(book.id).statusmsg)
Example #4
0
def create_book(name):
    """
    creates new book - split to chapters and creates book file
    :param name: the epub file name
    """
    # check if the book is already in the system
    if Book.is_book_exists(name):
        raise BookNameException
    # create new book
    Book.create_new_book(name)
Example #5
0
def create_book(name, link, rate):
    book = Book()

    author = re.split(' - ', name)[0]
    book.set_author(author)

    title = re.split(' - ', name)[1]
    book.set_title(title)

    book.set_link(str(link))

    book.set_rate(int(rate))

    return book
Example #6
0
 def test_medium_minhashexcludes(self): #Minhash must exclude at least some misses!
     testmgr = zTestDataManager.TestBookManager('samplebooks.zip','../testbooks/')
     testmgr.unpack_archive(max=10)
     testbook = testmgr.get_testbooks()[0]
     e = zTestDataManager.ErrorMaker()
     dupe = testmgr.make_error_dupes([testbook,], errormaker=e)[0]
     books = testmgr.get_testbooks()
     library = Library.Library()
     for book in books:
         mybook = Book(textfile=book)
         mybook.initialize_text_data()
         library.add_book(mybook)
     dupe = library.get_book_textfile(dupe)
     testablebook = library.get_book_textfile(testbook)
     possiblematches = library.get_possible_matches(testablebook)
     self.assertLess(len(possiblematches), 5, msg="minhash was not able to eliminate at least one possible book")
     self.assertGreaterEqual(len(possiblematches), 1, msg="minhash didn't get at least one hit")
     minverification = testmgr.verify_minhash_results(library)
     testmgr.print_formatted_minhash_results(minverification)
Example #7
0
 def test_medium_minhashfindsmatches(self): #make certain minhash actually...works.
     testmgr = zTestDataManager.TestBookManager('samplebooks.zip','../testbooks/')
     testmgr.unpack_archive(max=2)
     testbook = testmgr.get_testbooks()[0]
     e = zTestDataManager.ErrorMaker()
     dupe = testmgr.make_error_dupes([testbook,], errormaker=e)[0]
     books = testmgr.get_testbooks()
     library = Library.Library()
     for book in books:
         mybook = Book(textfile=book)
         mybook.initialize_text_data()
         library.add_book(mybook)
     dupe = library.get_book_textfile(dupe)
     testablebook = library.get_book_textfile(testbook)
     possiblematches = library.get_possible_matches(testablebook)
     found = False
     for id, score in possiblematches:
         if id == dupe.id:
             found=True
     self.assertTrue(found)
Example #8
0
def getBooksJson():
    jsonarr = []

    for index in range(len(booksList)):
        #Filter html file under the director
        if booksList[index].endswith(".html"):

            book = BeautifulSoup(open('static/ChallengeBooks/'+booksList[index]), "html.parser")
            bookName = book.title.string
            authorName = book.h4.find_next(re.compile('^h')).string
            bookURL = URLHeader+url_for('static', filename='ChallengeBooks/')+booksList[index]
            bookImageURL = URLHeader+url_for('static', filename='BooksImages/')+booksImageList[index]

            i = Book(index, bookName, authorName, bookURL, bookImageURL)

            jsonarr.append({'bookId':i.getBookId(), 'bookName':i.getBookName(), 'authorName':i.getAuthorName(),
                'bookURL':i.getBookURL(), 'bookImageURL':i.getBookImageURL()})

    #Turn jsonarr into json object
    return json.dumps(jsonarr)
    def create_book(self):
        """create book"""
        (category, title, price) = self.view.create_book()
        objBook = Book()
        objBook.id_category = category
        objBook.title = title
        objBook.price = price
        objBook.create()

        self.view.show_message_created()
        self.book_main_controller()
def getParsedContent():
    bookName = ""

    bible = Bible()
    book = Book("Genesis")
    chapter = Chapter(1)

    file = open("bible.txt")
    bookname = ""
    for line in  file:
	    splitLine = line.split()

	    # Aquires Book Title Name of current line
	    if (splitLine[0].isdigit()):
		    bookName = splitLine[0] + " " + splitLine[1]
	    elif (splitLine[0] == "Song"):
		    bookName = splitLine[0] + " " + splitLine[1] + " " + splitLine[2]
	    else:
		    bookName = splitLine[0]

	    # Aquires Book Chapter number and verse number of current line
	    if (splitLine[0].isdigit()):
		    chapNumAndVerseNum = splitLine[2].split(sep=":")
	    elif (splitLine[0] == "Song"):
		    chapNumAndVerseNum = splitLine[3].split(sep=":")
	    else:
		    chapNumAndVerseNum = splitLine[1].split(sep=":")

	    # Uses chapNumandVerseNum to get the chapter number
	    # and the verse Number
	    currentChapNum = chapNumAndVerseNum[0]
	    currentVerseNum = chapNumAndVerseNum[1]

	    verseString = ""

	    # Aquires the Verse String from the current line.
	    if (splitLine[0].isdigit()):
		    for index in range(3, len(splitLine)):
		        verseString += splitLine[index] + " "
	    elif (splitLine[0] == "Song"):
		    for index in range(4, len(splitLine)):
		        verseString += splitLine[index] + " "
	    else:
		    for index in range(2, len(splitLine)):
		        verseString += splitLine[index] + " "

	    # Uses generated verse String to create a new bible verse
	    currentBibleVerse = Verse(currentVerseNum, verseString)

	    # When Book Title Changes, add the current book to the bible.
	    # Then, create new book.
	    if (book.bookTitle != bookName):
		    book.addChapter(chapter)
		    chapter = Chapter(currentChapNum)
		    bible.addBook(book.bookTitle, book)
		    book = Book(bookName)  # Resets Book Object
		    book.bookTitle = bookName

	    # When Book Number Changes, add the current chapter to the current book
	    # Then, Create a new book.
	    elif(currentChapNum != chapter.chapterNum):
	        book.addChapter(chapter)
	        chapter = Chapter(currentChapNum)

	    # Adds each verse to the correct chapter
	    chapter.addVerse(currentBibleVerse)

	# Adds Revelations [Edge Case]
    book.addChapter(chapter)
    bible.addBook(bookName, book)
    return bible
 def displayCompleteInfo(self):
     print Book.getBasicInformation(self) + ", Year: " + str(self.year)
 def __init__(self, name, author, year):
     Book.__init__(self, name, author)
     self.year = year
Example #13
0
from Book import Book
import pickle
import time

"""
This file just for create some sample book object to database
"""

if __name__ == '__main__':
    book_list = []

    my_book = Book("Four in Camp","QUINNEYS.jpg", 20)
    my_book.author = "Ralph Henry Barbour"
    my_book.summary = "A STORY OF SUMMER ADVENTURES IN THE NEW HAMPSHIRE WOODS"
    my_book.type = "Adventures"
    my_book.NumOfRead = 18
    my_book.cover_page = "QUINNEYS.jpg"
    my_book.book_file = "Four in Camp.txt"
    my_book.contribute_by = "kaiying"
    my_book.last_time_read = time.time()
    my_book.superuser_set_point = 0
    my_book.complain = []
    my_book.last_time_read = time.time()
    book_list.append(my_book)

    my_book = Book("La chair et le sang","QUINNEYS.jpg", 5)
    my_book.author = "Franois Mauriac"
    my_book.summary = "Since the introduction of the tungsten lamp some five years ago," \
                      " the manufacturers have attempted continually to produce smaller " \
                      "and smaller units in the standard voltages."
    my_book.type = "Education"
 def getBooks(self):
     book = Book()
     books = book.read_all()
     return books
    def CollectData(self):
        book = Book()

        if self.imagePath is not None:
            book.setImage(self.imagePath)
        elif self.book is not None:
            book.setImage(self.book.getImage())

        book.setTitle(str(self.titleCtrl.GetValue()))
        book.setAuthor(str(self.authorsCtrl.GetValue()))
        book.setGenre(str(self.genresCtrl.GetValue()))
        book.setPublisher(str(self.publisherCtrl.GetValue()))
        book.setNbPages(int(self.pagesCtrl.GetValue()))
        book.setIsbn(str(self.isbnCtrl.GetValue()))
        book.setLocation(str(self.placeCtrl.GetValue()))
        book.setRating(self.gradeCtrl.GetValue())
        
        borrower = str(self.borrower.GetValue()).strip()
        
        if borrower != "":
            book.setTenant(borrower)
            book.setDateBorrow(_wxdate2pydate(self.borrowDate.GetValue()))
            book.setDateReturned(_wxdate2pydate(self.returnDate.GetValue()))

        return book
def allBooks():
    books = []
    for entry in redis.smembers("books"):
        books.append(Book.from_string(entry))
    return books
Example #17
0
    def ConvertToBook(self):
        book = Book()
        book.setID(self.id)
        book.setTitle(self.title)
        book.setAuthor(self.authors)
        book.setIsbn(self.ISBN)
        book.setNbPages(self.pages)
        book.setGenre(self.genre)
        book.setPublisher(self.publisher)     
        book.setImage(self.image)
        book.setRating(self.grade)
        book.setLocation(self.location)
        book.setTenant(self.tenant)
        book.setDateBorrow(self.dateBorrow)
        book.setDateReturned(self.dateReturned)

        return book
	def fileProcessing(self):
		
		with open("book.txt" , 'r') as bookObj:
			for line in bookObj:
				fields = line.split('|')
				
				l0 = fields[0]
				l1 = fields[1]
				l2 = fields[2]
				l3 = fields[3]
				l4 = fields[4]
				l5 = fields[5]
				l6 = fields[6]
				l7 = fields[7]
				l8 = fields[8]
				l9 = fields[9]
				book = Book(l0,l1,l2,l3,l4,l5,l6,l7,l8,l9)
				book.__class__ = Book
				cardCatalog.append(book)
			
			#for obj in cardCatalog:
				#obj.display()
				#print len(cardCatalog)

		with open("periodic.txt" , 'r') as periodicObj:
			for line in periodicObj:
				fields = line.split('|')
				
				l0 = fields[0]
				l1 = fields[1]
				l2 = fields[2]
				l3 = fields[3]
				l4 = fields[4]
				l5 = fields[5]
				l6 = fields[6]
				l7 = fields[7]
				l8 = fields[8]
				l9 = fields[9]
				l10 = fields[10]
				l11 = fields[11]
				periodic = Periodic(l0,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11)
				periodic.__class__ = Periodic
				cardCatalog.append(periodic)


		with open("video.txt" , 'r') as videoObj:
			for line in videoObj:
				fields = line.split('|')
				
				l0 = fields[0]
				l1 = fields[1]
				l2 = fields[2]
				l3 = fields[3]
				l4 = fields[4]
				l5 = fields[5]
				l6 = fields[6]
				l7 = fields[7]
				
				video = Video(l0,l1,l2,l3,l4,l5,l6,l7)
				video.__class__ = Video
				cardCatalog.append(video)



		with open("film.txt" , 'r') as filmObj:
			for line in filmObj:
				fields = line.split('|')
				
				l0 = fields[0]
				l1 = fields[1]
				l2 = fields[2]
				l3 = fields[3]
				l4 = fields[4]
				l5 = fields[5]
				film = Film(l0,l1,l2,l3,l4,l5)
				film.__class__ = Film
				cardCatalog.append(film)
Example #19
0
    def ConvertToBook(self):
        book = Book()
        book.setTitle(self.title)
        book.setAuthor(self.authors)
        book.setIsbn(self.ISBN)
        book.setNbPages(self.pages)
        book.setPublisher(self.publisher)     
        book.setImageURL(self.imageURL)

        return book