Advertisement
Guest User

calcWeather()

a guest
Nov 23rd, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import jsonData from "./json/data.json";
  2. //const jsonData = require('./json/data.json')
  3.  
  4. async function calcWeather() {
  5.   // let rawdata = fs.readFileSync("./json/data.json");
  6.   // let data2 = JSON.parse(rawdata);
  7.  
  8.   // fs.readFile("./json/data.json", "utf8", function (err, data) {
  9.   //   if (err) throw err;
  10.   //   data2 = JSON.parse(data /*[0]*/);
  11.  
  12.   //   console.log(typeof data2);
  13.     for (let item of jsonData) {
  14.       let base = `https://api.openweathermap.org/data/2.5/weather?lat=${item.latjson}&lon=${item.lonjson}&appid=${api_key}&units=metric&lang=sp`;
  15.  
  16.       fetch(base)
  17.         .then((responses) => {
  18.           return responses.json();
  19.         })
  20.         .then((data) => {
  21.           var myObject = {
  22.             Id_Oficina: item.IdOficina,
  23.             Humedad: data.main.humidity,
  24.             Nubes: data.clouds.all,
  25.             Sensacion: data.main.feels_like,
  26.             Temperatura: data.main.temp,
  27.             Descripcion: data.weather.description,
  28.           };
  29.           // validation and saving data to array
  30.           if (myObject.Temperatura < 99) {
  31.             lstValid.push(myObject);
  32.           }
  33.         });
  34.     }
  35.   // });
  36.   console.log(lstValid);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement