Skip to content

Commit

Permalink
Add support for air quality index
Browse files Browse the repository at this point in the history
  • Loading branch information
riyadhalnur committed Aug 31, 2019
1 parent 7d8e01b commit 39de3ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ if (cli.input.length && cli.input[0] === 'config') {
console.log(chalk.red(`${result.city}, ${result.country}`));
console.log(chalk.cyan(`Condition: ${chalk.yellow(result.condition)}`));
console.log(chalk.cyan(`Temperature: ${chalk.yellow(result.temp)}${chalk.yellow('°' + result.scale)}`));

if (result.aqi) {
console.log(chalk.cyan(`Air Quality: ${chalk.yellow(result.aqi)} ${chalk.yellow(weather.mapAQI(result.aqi))}`));
}
process.exit(0);
}).catch(err => {
if (err) {
Expand Down
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,20 @@ module.exports = {

resolve(`Default location set to ${opts.city}, ${opts.country} and scale to ${opts.scale ? opts.scale : 'C'}`);
});
},
mapAQI: (aqi) => {
if (aqi >= 0 && aqi <= 50) {
return 'Good';
} else if (aqi >= 51 && aqi <= 100) {
return 'Moderate';
} else if (aqi >= 101 && aqi <= 150) {
return 'Unhealthy for sensitive groups';
} else if (aqi >= 151 && aqi <= 200) {
return 'Unhealthy';
} else if (aqi >= 201 && aqi <= 300) {
return 'Very Unhealthy';
} else if (aqi > 300) {
return 'Hazardous';
}
}
};

0 comments on commit 39de3ad

Please sign in to comment.