Guest User

Untitled

a guest
May 12th, 2025
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const buffer = E.toArrayBuffer(atob(jsonData.d));
  2. const binary = new Uint8Array(buffer);
  3.  
  4. const weather = json2.weather;
  5. let offset = 0;
  6.  
  7. weather.temp = binary[offset++] + 150;
  8. weather.hi = binary[offset++] + 150;
  9. weather.lo = binary[offset++] + 150;
  10. weather.hum = binary[offset++];
  11. weather.rain = binary[offset++];
  12. weather.uv = binary[offset++] / 10;
  13. weather.code = binary[offset++] + (binary[offset++] << 8);
  14. const res1 = decodeString(binary, offset++);
  15. offset += res1[0];
  16. weather.txt = res1[1];
  17. weather.wind = (binary[offset++] + (binary[offset++] << 8)) / 100;
  18. weather.wdir = binary[offset++] + (binary[offset++] << 8);
  19. weather.wrose = windDirection(weather.wdir);
  20. const res2 = decodeString(binary, offset++);
  21. offset += res2[0];
  22. weather.loc = res2[1];
  23. weather.dew = binary[offset++] + 150;
  24. weather.pres = (binary[offset++] + (binary[offset++] << 8)) / 10;
  25. weather.cloud = binary[offset++];
  26. weather.visib = (binary[offset++] + (binary[offset++] << 8) + (binary[offset++] << 16) + (binary[offset++] << 24)) / 10;
  27. weather.sunrise = binary[offset++] + (binary[offset++] << 8) + (binary[offset++] << 16) + (binary[offset++] << 24);
  28. weather.sunset = binary[offset++] + (binary[offset++] << 8) + (binary[offset++] << 16) + (binary[offset++] << 24);
  29. weather.moonrise = binary[offset++] + (binary[offset++] << 8) + (binary[offset++] << 16) + (binary[offset++] << 24);
  30. weather.moonset = binary[offset++] + (binary[offset++] << 8) + (binary[offset++] << 16) + (binary[offset++] << 24);
  31. weather.moonphase = binary[offset++] + (binary[offset++] << 8);
  32. weather.feel = binary[offset++] + 150;
  33.  
  34. weather.hourfcast = [];
  35. weather.dayfcast = [];
  36. if (offset < binary.length && parseForecast) {
  37.   // We have forecast data
  38.   const hoursAmount = binary[offset++];
  39.   if (hoursAmount > 0) {
  40.     const timestampBase = (binary[offset++] + (binary[offset++] << 8) + (binary[offset++] << 16) + (binary[offset++] << 24));
  41.  
  42.     for (let i = 0; i < hoursAmount; i++) {
  43.       weather.hourfcast[i] = {};
  44.       weather.hourfcast[i].time =
  45.         timestampBase + (binary[offset++] / 10) * 3600;
  46.       weather.hourfcast[i].temp = binary[offset++] + 150;
  47.       weather.hourfcast[i].code = binary[offset++] + (binary[offset++] << 8);
  48.       weather.hourfcast[i].wind =
  49.         (binary[offset++] + (binary[offset++] << 8)) / 100;
  50.       weather.hourfcast[i].wdir = binary[offset++] + (binary[offset++] << 8);
  51.       weather.hourfcast[i].wrose = windDirection(weather.hourfcast[i].wdir);
  52.       weather.hourfcast[i].rain = binary[offset++];
  53.     }
  54.   }
  55.  
  56.   const daysAmount = binary[offset++];
  57.   for (let i = 0; i < daysAmount; i++) {
  58.     weather.dayfcast[i] = {};
  59.     weather.dayfcast[i].hi = binary[offset++] + 150;
  60.     weather.dayfcast[i].lo = binary[offset++] + 150;
  61.     weather.dayfcast[i].code = binary[offset++] + (binary[offset++] << 8);
  62.     weather.dayfcast[i].wind =
  63.       (binary[offset++] + (binary[offset++] << 8)) / 100;
  64.     weather.dayfcast[i].wdir = binary[offset++] + (binary[offset++] << 8);
  65.     weather.dayfcast[i].wrose = windDirection(weather.dayfcast[i].wdir);
  66.     weather.dayfcast[i].rain = binary[offset++];
  67.   }
  68. }
  69.  
  70. return json2;
Advertisement
Add Comment
Please, Sign In to add comment