Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let ipURL = `https://api.ipify.org?format=json`;
- let ip;
- let location;
- let weatherCondition = "Rainnyyy";
- let locationURL;
- let openWeatherURL;
- let city = "gummersbach";
- let cityID = "2913761";
- request(ipURL, function (err, response, body) {
- if (err) {
- console.log("error:", error);
- } else {
- let temp = JSON.parse(body);
- ip = temp.ip;
- console.log(ip);
- locationURL = `http://ip-api.com/json/${ip}?fields=city&lang=de`;
- }
- request(locationURL, function (err, response, body) {
- if (err) {
- console.log("error:", error);
- } else {
- let temp = JSON.parse(body)
- location = temp.city;
- console.log(location);
- openWeatherURL = `http://api.openweathermap.org/data/2.5/weather?q=${location}&units=metric&APPID=${openWeatherApiKey}`;
- }
- request(openWeatherURL, function (err, response, body) {
- if (err) {
- console.log("error:", error);
- } else {
- let weather = JSON.parse(body);
- weatherCondition = weather.weather[0].id;
- if (/7[0-9][0-9]/.test(weatherCondition)) {
- weatherCondition = 'Clouds';
- }
- let message = `Es ist ${weather.main.temp}° Celsius in ${weather.name}! und condition ist ${weatherCondition}`
- console.log(message);
- }
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement