Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. let ipURL = `https://api.ipify.org?format=json`;
  2. let ip;
  3. let location;
  4. let weatherCondition = "Rainnyyy";
  5. let locationURL;
  6. let openWeatherURL;
  7. let city = "gummersbach";
  8. let cityID = "2913761";
  9.  
  10. request(ipURL, function (err, response, body) {
  11. if (err) {
  12. console.log("error:", error);
  13. } else {
  14. let temp = JSON.parse(body);
  15. ip = temp.ip;
  16. console.log(ip);
  17. locationURL = `http://ip-api.com/json/${ip}?fields=city&lang=de`;
  18. }
  19.  
  20. request(locationURL, function (err, response, body) {
  21. if (err) {
  22. console.log("error:", error);
  23. } else {
  24. let temp = JSON.parse(body)
  25. location = temp.city;
  26. console.log(location);
  27. openWeatherURL = `http://api.openweathermap.org/data/2.5/weather?q=${location}&units=metric&APPID=${openWeatherApiKey}`;
  28. }
  29.  
  30. request(openWeatherURL, function (err, response, body) {
  31. if (err) {
  32. console.log("error:", error);
  33. } else {
  34. let weather = JSON.parse(body);
  35. weatherCondition = weather.weather[0].id;
  36. if (/7[0-9][0-9]/.test(weatherCondition)) {
  37. weatherCondition = 'Clouds';
  38. }
  39. let message = `Es ist ${weather.main.temp}° Celsius in ${weather.name}! und condition ist ${weatherCondition}`
  40. console.log(message);
  41. }
  42. });
  43. });
  44. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement