Created
January 7, 2017 22:05
-
-
Save shershen08/d664ce3674cf1c655430864deab01df0 to your computer and use it in GitHub Desktop.
Weather forecast from IP recipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('request'); | |
const APIKEY = require('./weather_apikey'); //file with '{"key": "XXX"}' | |
const ip = '208.67.222.222'; | |
const getLatLng = (ip) => { | |
const url = `https://ipapi.co/${ip}/latlong/`; | |
request.get(url) | |
.on('response', function (response) { | |
if (response.statusCode == 200) getWeather(response.body); | |
}); | |
} | |
const getWeather = (latLngArray) => { | |
const url = `http://api.openweathermap.org/data/2.5/weather?lat= | |
${latLngArray[0]}&lon=${latLngArray[1]}&appid=${API_KEY.key}`; | |
request.get(url) | |
.on('response', function (response) { | |
if (response.statusCode == 200) console.log(response.body); | |
}); | |
} | |
getLatLng(ip); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment