diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..767cb57 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,8 @@ +{ + "parser": "babel-eslint", + "env": { + "es6": true, + "node": true + }, + "extends": "standard" +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb79dd5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +.idea diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..3ef441f --- /dev/null +++ b/.npmignore @@ -0,0 +1,7 @@ +.gitignore +.npmignore + +node_modules/ +npm-debug.log + +.idea/ diff --git a/README.md b/README.md index 26c1c12..5265b41 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,18 @@ # pogodka Get current weather, from console + +## Installing + +Install package globaly with command: + +`npm i pogodka -g` + +## Usage + +Just type in command line, one of these commands: + +- `pogodka` +- `pogoda` +- `pgd` +- `weather` +- `wthr` diff --git a/index.js b/index.js new file mode 100755 index 0000000..4279227 --- /dev/null +++ b/index.js @@ -0,0 +1,23 @@ +#! /usr/bin/env node + +const geoip = require('geoip-lite') +const extIP = require('ext-ip')() +const request = require('request') + +const apiKey = 'f2d5b989dfafdab237be56401ef53185' + +extIP.get().then(ip => { + const geo = geoip.lookup(ip) + const req = 'http://api.openweathermap.org/data/2.5/weather?' + request(`${req}lat=${geo.ll[0]}&lon=${geo.ll[1]}&appid=${apiKey}&units=metric`, + (err, res, body) => { + if (!err) { + const response = JSON.parse(body) + console.log(`Current temperature in ${response.name}: ${response.main.temp}`) + } else { + console.log(`Can't get weather. Try again.\nMore: ${err}`) + } + }) +}, err => { + console.error(`Can't get your location.\nMore: ${err}`) +}) diff --git a/package.json b/package.json new file mode 100644 index 0000000..9660760 --- /dev/null +++ b/package.json @@ -0,0 +1,43 @@ +{ + "version": "0.0.1", + "author": { + "name": "Oleh Aloshkin" + }, + "bin": { + "pogodka": "./index.js", + "weather": "./index.js" + }, + "bugs": { + "url": "https://github.com/AleshaOleg/pogodka/issues" + }, + "dependencies": { + "ext-ip": "^0.3.8", + "geoip-lite": "^1.2.1" + }, + "description": "Get current weather, from console", + "devDependencies": { + "babel-eslint": "^7.2.3", + "eslint": "^4.4.0", + "eslint-config-standard": "^10.2.1", + "eslint-plugin-import": "^2.7.0", + "eslint-plugin-node": "^5.1.1", + "eslint-plugin-promise": "^3.5.0", + "eslint-plugin-standard": "^3.0.1" + }, + "gitHead": "ee22710e008046226a4cc9fba94c88c0f6e2e15d", + "homepage": "https://github.com/AleshaOleg/pogodka#readme", + "keywords": [ + "weather", + "console-weather" + ], + "license": "ISC", + "main": "index.js", + "name": "pogodka", + "optionalDependencies": {}, + "readme": "# pogodka\nGet current weather, from console\n", + "readmeFilename": "README.md", + "repository": { + "type": "git", + "url": "git+https://github.com/AleshaOleg/pogodka.git" + } +}