All Projects → alexellis → pi_zero_stock

alexellis / pi_zero_stock

Licence: GPL-3.0 license
PI Zero Stock tracker in Node.js with Redis back-end to cache results

Programming Languages

HTML
75241 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].