Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const buffer = E.toArrayBuffer(atob(jsonData.d));
- const binary = new Uint8Array(buffer);
- const weather = json2.weather;
- let offset = 0;
- weather.temp = binary[offset++] + 150;
- weather.hi = binary[offset++] + 150;
- weather.lo = binary[offset++] + 150;
- weather.hum = binary[offset++];
- weather.rain = binary[offset++];
- weather.uv = binary[offset++] / 10;
- weather.code = binary[offset++] + (binary[offset++] << 8);
- const res1 = decodeString(binary, offset++);
- offset += res1[0];
- weather.txt = res1[1];
- weather.wind = (binary[offset++] + (binary[offset++] << 8)) / 100;
- weather.wdir = binary[offset++] + (binary[offset++] << 8);
- weather.wrose = windDirection(weather.wdir);
- const res2 = decodeString(binary, offset++);
- offset += res2[0];
- weather.loc = res2[1];
- weather.dew = binary[offset++] + 150;
- weather.pres = (binary[offset++] + (binary[offset++] << 8)) / 10;
- weather.cloud = binary[offset++];
- weather.visib = (binary[offset++] + (binary[offset++] << 8) + (binary[offset++] << 16) + (binary[offset++] << 24)) / 10;
- weather.sunrise = binary[offset++] + (binary[offset++] << 8) + (binary[offset++] << 16) + (binary[offset++] << 24);
- weather.sunset = binary[offset++] + (binary[offset++] << 8) + (binary[offset++] << 16) + (binary[offset++] << 24);
- weather.moonrise = binary[offset++] + (binary[offset++] << 8) + (binary[offset++] << 16) + (binary[offset++] << 24);
- weather.moonset = binary[offset++] + (binary[offset++] << 8) + (binary[offset++] << 16) + (binary[offset++] << 24);
- weather.moonphase = binary[offset++] + (binary[offset++] << 8);
- weather.feel = binary[offset++] + 150;
- weather.hourfcast = [];
- weather.dayfcast = [];
- if (offset < binary.length && parseForecast) {
- // We have forecast data
- const hoursAmount = binary[offset++];
- if (hoursAmount > 0) {
- const timestampBase = (binary[offset++] + (binary[offset++] << 8) + (binary[offset++] << 16) + (binary[offset++] << 24));
- for (let i = 0; i < hoursAmount; i++) {
- weather.hourfcast[i] = {};
- weather.hourfcast[i].time =
- timestampBase + (binary[offset++] / 10) * 3600;
- weather.hourfcast[i].temp = binary[offset++] + 150;
- weather.hourfcast[i].code = binary[offset++] + (binary[offset++] << 8);
- weather.hourfcast[i].wind =
- (binary[offset++] + (binary[offset++] << 8)) / 100;
- weather.hourfcast[i].wdir = binary[offset++] + (binary[offset++] << 8);
- weather.hourfcast[i].wrose = windDirection(weather.hourfcast[i].wdir);
- weather.hourfcast[i].rain = binary[offset++];
- }
- }
- const daysAmount = binary[offset++];
- for (let i = 0; i < daysAmount; i++) {
- weather.dayfcast[i] = {};
- weather.dayfcast[i].hi = binary[offset++] + 150;
- weather.dayfcast[i].lo = binary[offset++] + 150;
- weather.dayfcast[i].code = binary[offset++] + (binary[offset++] << 8);
- weather.dayfcast[i].wind =
- (binary[offset++] + (binary[offset++] << 8)) / 100;
- weather.dayfcast[i].wdir = binary[offset++] + (binary[offset++] << 8);
- weather.dayfcast[i].wrose = windDirection(weather.dayfcast[i].wdir);
- weather.dayfcast[i].rain = binary[offset++];
- }
- }
- return json2;
Advertisement
Add Comment
Please, Sign In to add comment