npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

openbookprices-fetchers

v0.0.4

Published

Code for getting the prices of books from various vendors

Downloads

3

Readme

OpenBookPrices Price Fetchers

Build Status

This repository contains the code that is used to fetch the price and other information for a particular book from a particular vendor.

How the price is fetched varies from an API call to scraping the vendor's website.

The extracted information is returned in a standard form that can then be cleaned up as needed.

Return format

The response is a hash, looking something like this:

{
  "args": {
    "country": "GB",
    "currency": "GBP",
    "isbn": "9780330508537",
    "vendor": "foyles"
  },
  "authors": [
    "Douglas Adams"
  ],
  "title": "The Hitchhiker's Guide to the Galaxy",
  "url": "http://www.foyles.co.uk/witem/fiction-poetry/the-hitchhikers-guide-to-the-galaxy,douglas-adams-9780330508537",
  "entries": [
    {
      "countries": [
        "GB"
      ],
      "currency": "GBP",
      "offers": {
        "new": {
          "availabilityNote": "Despatched in 1 business day.",
          "price": 5.83,
          "shipping": 2.5,
          "shippingNote": "Free second class delivery in the UK for orders over £10",
          "total": 8.33
        }
      },
      "isbn": "9780330508537",
      "timestamp": 1371993232,
      "ttl": 86400,
      "url": "http://www.foyles.co.uk/witem/fiction-poetry/the-hitchhikers-guide-to-the-galaxy,douglas-adams-9780330508537",
      "vendor": "foyles"
    },
    ...
  ]
}

Guide to the keys

authors and title

Text. These fields are optional, but it is nice if they are included.

entries

Array. The entries array should contain an entry for each combination of country and currency (note that countries is an array, as often lots of countries will have the same price). The availability flag is true if the vendor can supply this book, false otherwise. What canSell means is something that each scrapers needs to determine, but generally true mean that they can sell it, and false means they can (don't stock it, book not found on their site, out of stock etc).

The 'shipping' and hence 'total' returned assume that you are only buying the one book. The shippingNote should be used to clarify if there are discounts to be had for buying more (as in the above example).

The url is to the page on the vendor's site for this book.

Note that the format is similar to, but different from, the format returned by the OpenBookPrices API.

Proxy

During development it is convenient to run a proxy that cache all requests so that the time taken to run a scraper is much shorter, and it is politer to the target site too. Polipo works well for this:

# install using your package manager of choice, in this case brew
brew install polipo

# run polipo in a separate terminal telling it to cache everything once fetched
polipo -- relaxTransparency=true logLevel=0xFF idleTime=1s

# in the terminal where you run the scripts set the env variable
export http_proxy=http://localhost:8123/

# When you want to clear the cache just delete the files (adapt to your system)
rm -r /usr/local/var/cache/polipo/*