Skip to content
Snippets Groups Projects
JsonParser.py 1.53 KiB
Newer Older
  • Learn to ignore specific revisions
  • 
    def parse_book_dict_to_json(dictionary):
        item_list = list(dictionary.items())
        return_list = []
        for items in item_list:
            book_package = items[1]
            book_json = parse_book_to_json(book_package)
            return_list.append(book_json)
        return return_list
    
    
    def parse_author_dict_to_json(dictionary):
        item_list = list(dictionary.items())
        return_list = []
        for items in item_list:
            author_package = items[1]
            author_json = parse_author_to_json(author_package)
            return_list.append(author_json)
        return return_list
    
    
    def parse_book_to_json(bookPKT):
        book_json = {
            "type": "book",
            "book_url": bookPKT.url,
            "title": bookPKT.title,
            "id": bookPKT.id,
            "ISBN": bookPKT.ISBN13,
            "author_url": bookPKT.author_url,
            "author": bookPKT.author,
            "rating": bookPKT.rating,
            "rating_count": bookPKT.rating_count,
            "review_count": bookPKT.review_count,
            "image_url": bookPKT.image_url,
            "similar_books": bookPKT.similar_books
        }
        return book_json
    
    
    def parse_author_to_json(authorPKT):
        author_json = {
            "type": "author",
            "name": authorPKT.name,
            "author_url": authorPKT.url,
            "id": authorPKT.id,
            "rating": authorPKT.rating,
            "rating_count": authorPKT.rating_count,
            "review_count": authorPKT.review_count,
            "image_url": authorPKT.image_url,
            "related_authors": authorPKT.related_authors,
            "author_books": authorPKT.author_books
        }
        return author_json