Giter VIP home page Giter VIP logo

purpleair's Introduction

purpleair

Retrieve AQI (with AQandU conversion) from a PurpleAir sensor via the CLI or as a library to your node script

Most of this code was stolen from https://aqi.wtf

determine your purpleair sensor ID

Open the PurpleAir map: https://www.purpleair.com/map?mylocation

and click on the sensor closest to your location.

The URL bar will change to something like:

https://www.purpleair.com/map?opt=1/mAQI/a10/cC0&select=62217#15.69/37.737125/-122.414218

The sensor ID will be the value of the select parameter. In the above URL, the ID is 62217:

https://www.purpleair.com/map?opt=1/mAQI/a10/cC0&select=62217#15.69/37.737125/-122.414218

cli usage

Install the module globally

npm install -g purpleair

Then call:

purpleair [sensor ID]

which will return the AQI.

Example output:

> purpleair 62217
139

With the AQI class:

> purpleair --class 62217
139 (unhealthy-for-sensitive-groups)

As JSON:

> purpleair --class --json 62217
{
  "aqi": 139,
  "sensorId": 62217,
  "class": "unhealthy-for-sensitive-groups"
}

library usage

There are three functions:

  • getSensor(sensorId)
  • getAQI(sensor)
  • getAQIClass(aqi)

Example:

const purpleair = require('purpleair');

const main = async () => {
    try {

        var sensor = await purpleair.getSensor(62217);
        var aqi = await purpleair.getAQI(sensor);

        console.log(aqi);

        var aqiClass = purpleair.getAQIClass(aqi);

        console.log(aqiClass);

    } catch (err) {
        console.error(err);
    }
};

main();

License

MIT

purpleair's People

Contributors

bertrandom avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

jhurstus

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.