@jakubzitny/openweathermap-cli
v1.1.0
Published
Display weather info for a city from OpenWeatherMap API
Downloads
12
Readme
OpenWeatherMap CLI
Display weather info for a city from OpenWeatherMap API, interactively, from command line or from a config.
Usage
Make sure you have OPENWEATHERMAP_API_KEY
in env when running this app. Get it at openweathermap.org.
Install:
npm install -g @jakubzitny/openweathermap-cli
export OPENWEATHERMAP_API_KEY="your key"
openweathermap-cli -h
Or on Windows:
npm install -g @jakubzitny/openweathermap-cli
$Env:OPENWEATHERMAP_API_KEY="your key"
# Make sure you can run NPM global scripts
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
openweathermap-cli -h
Examples:
openweathermap-cli # no args
- will ask interactively for a location with detected current cityopenweathermap-cli -c Paris
- will provide info for Paris in °C (default)openweathermap-cli --city Prague -scale fahrenheit
- will provide info for Prague in °Fopenweathermap-cli -l
- will repeat the latest queryopenweathermap-cli -i locations.txt
- will provide info for locations from a text fileopenweathermap-cli --disable-geolocation
- will ask interactively without asking for a location
Options
Options:
-c, --city Specify the city [string]
-z, --zip Specify the zip code [string]
-l, --latest-query Use latest query [boolean]
-s, --scale Define a scale to use [string] [default: "celsius"]
-g, --disable-geolocation Disable geolocation (enabled by default)
[boolean] [default: false]
-i, --import Import a file with multiple locations [string]
-v, --version Show version number [boolean]
-h, --help Show help [boolean]
Allowed scale values are c
, f
, celsius
and fahrenheit
, celsius
is default if not specified.
Multiple locations config file
Specify up to 10 different cities or zip codes from a file (e.g. locations.txt
), each on a separate line, and import with -i
flag.
Paris
Barcelona
Prague
Stack
- Node.js (v12 LTS), Yarn, Babel, Flow
- ESlint, Prettier
- Jest, Chai, Sinon
- Got (requirement, used for API fetching)
- Yargs (great time saver when parsing CLI args)
Possible improvements
- better UX (not a CLI in the ideal scenario, who looks for the weather in CLI?)
- better API (this one is slow and limited, we should create our own and connect to different providers)
- better error handling, error messages, retrying, and caching
- dependency injection mechanism for clearer classes and better testing
- debug / log messages (if specified from command line)
CliParser
class could be refactored into smaller pieces and tested more thoroughly- code minification
- integration tests
Development
- Clone and install
git clone https://github.com/jakubzitny/openweathermap-cli
cd openweathermap-cli
yarn
- Build it
yarn build
- Check and test
yarn flow
yarn prettier
yarn lint
yarn test
- Run
yarn start --help
yarn start
yarn start -c Prague
# or with alias
alias openweathermap-cli="node bin/index.js"
openweathermap-cli --help
openweathermap-cli -c Prague
openweathermap-cli --city Paris -scale fahrenheit