Swiftpack.co - vinayjn/Bookshelf as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by vinayjn.
vinayjn/Bookshelf 2.0.2
A Swift package to build a bookshelf on my blog https://vinayjain.me/bookshelf/
⭐️ 2
🕓 3 weeks ago
macOS
.package(url: "https://github.com/vinayjn/Bookshelf.git", from: "2.0.2")

Bookshelf

Swift

A command-line tool that generates the bookshelf page on my website https://vinayjain.me/bookshelf.

preview

Installation

Add this package as a dependency in your project.

https://github.com/vinayjn/Bookshelf.git

Dependencies

  • Kanna for scrapping websites.

How does it work?

Bookshelf is simply a web scrapper, it fetches basic information of books from Goodreads. It expects two input arguments

  • A JSON file which is split into sections, each section represent a row in a real-world bookshelf. It has the following format:

    [
      {
        "header": "Currently Reading",
        "books": [
          {
            "goodreadsURL": "https://www.goodreads.com/book/show/40591677-keep-going"        
          },
          {
            "goodreadsURL": "https://www.goodreads.com/book/show/840.The_Design_of_Everyday_Things"        
          }      
        ]
      },
      {
        "header": "Read",
        "books": [
          {
            "goodreadsURL": "https://www.goodreads.com/book/show/11084145-steve-jobs"        
          },
          {
            "goodreadsURL": "https://www.goodreads.com/book/show/27833670-dark-matter"        
          }
        ]
      }
    ]
    
  • Path to an output file where the final HTML of the bookshelf will be written.

Each of these URLs represent a book and because the scrapper works by traversing the HTML document, it is necessary to provide the correct URLs else the data for the book won't be added. In the existing implementation, the scrapper looks for the following information:

  • title
  • thumbnail url
  • author names

These properties are then written back to the original input JSON to avoid scrapping for exisiting books in shelf.

[
  {
    "header" : "Currently Reading",
    "books" : [
      {
        "title" : "Keep Going: 10 Ways to Stay Creative in Good Times and Bad",
        "imageURL" : "images/bookshelf/afca15c8915d0ef2008995c803e9d62d.jpg",
        "goodreadsURL" : "https://www.goodreads.com/book/show/40591677-keep-going",
        "authors" : [
          "Austin Kleon"
        ]
      },
      {
        "title" : "The Design of Everyday Things",
        "imageURL" : "images/bookshelf/129ab3effe978b743bc1a58f918a4f87.jpg",
        "goodreadsURL" : "https://www.goodreads.com/book/show/840.The_Design_of_Everyday_Things",
        "authors" : [
          "Donald A. Norman"
        ]
      }
    ]
  },
  {
    "header" : "Read",
    "books" : [
      {
        "title" : "Steve Jobs",
        "imageURL" : "images/bookshelf/7f76ff8615d64e788ea5e9633def1625.jpg",
        "goodreadsURL" : "https://www.goodreads.com/book/show/11084145-steve-jobs",
        "authors" : [
          "Walter Isaacson"
        ]
      },
      {
        "title" : "Dark Matter",
        "imageURL" : "images/bookshelf/2360b31c1628a21ddd778891dabac91d.jpg",
        "goodreadsURL" : "https://www.goodreads.com/book/show/27833670-dark-matter",
        "authors" : [
          "Blake Crouch"
        ]
      }
    ]
  }
]

GitHub

link
Stars: 2
Last commit: 3 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics