def getSearchResultJson(): query = request.form['query'] 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) if query in i.getBookName().lower() or query in i.getAuthorName( ).lower(): 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 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)