PI Zero Stock tracker in Node.js with Redis back-end to cache results
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
poll
stock_fetch
web
.gitignore
LICENSE
README.md
docker-compose.yml
install.sh
rebuild.sh
start.sh

README.md

Raspberry PI Zero Stock Check

A high-speed, cached stock checker for the Raspberry PI Zero through screen-scraping.

See also:

Contributing:

Help is welcome, but my time is limited so if you have a suggestion, enhancement or bug fix then please raise an issue to begin a conversation.

Once an issue is open we can can talk about the proposed change in the open. Once we've figured out what needs to be done then you can go ahead and raise a PR and it's very likely to get merged.

Installation (easy way)

Using latest version of Docker and docker-compose:

$ git clone https://github.com/alexellis/pi_zero_stock
$ docker-compose up -d

Manual installation or development:

  • Install Node.js 4.x, Redis
  • npm install in stock_fetch and web folders
  • Start redis-server
  • npm start in both folders.

Set up a hosts entry in /etc/hosts for redis to localhost, or set the environmental variable 'REDIS' to localhost before starting any of the nodes processes.

Supported endpoints:

I've implemented endpoints for the following stores:

UK-based

  • pimoroni
  • pihut
  • pisupply

US-based

  • adafruit

To extend the code and add a new endpoint look at the stock_fetch project and add a new file under the fetch folder. This also needs to be updated in the entrypoint of stock_fetch.

Accessing the API:

curl http://localhost:3000/stock/pimoroni/
curl http://localhost:3000/stock/pisupply/
curl http://localhost:3000/stock/pihut/
  • 200 is given if cache is valid and the stock will be returned as true or false.
  • 202 means the check was in progress, send the request again.

Viewing in web-browser

Access the following:

http://localhost:3000/

Hosting the site

  • See the Docker installation
  • Use nginx to forward requests on port 80 to the local machine on port 3000

Todo:

[x] Must have - hardening for failures during scrape
[x] Should have - total stock numbers for any Raspberry PI bundles/products by store.
[x] Should have - (Static site) Angular 1.x (via CDN) for binding stock results. 
[ ] Should have - Switch to pm2 for the node processes
[x] Should have - coloured bootstrap wells or pills for in/out of stock.
[ ] Could have - web hooks (posting to Twitter)
[x] Could have - show stock for other suppliers. (adafruit)
[ ] Could have - show stock units for individual SKUs, rather than (or in addition to) just one total-per-shop