Skip to content

Commit

Permalink
weather
Browse files Browse the repository at this point in the history
  • Loading branch information
ShazimC committed Oct 4, 2021
1 parent 4e8a668 commit 5a4a3d2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
Binary file modified SalahWatchFace.wgt
Binary file not shown.
3 changes: 0 additions & 3 deletions data/weather.json

This file was deleted.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>

<div id="measurements">
<div id="weather-text">23º</div>
<div id="weather-text">..</div>
<div id="battery-text">..</div>
</div>

Expand Down
44 changes: 35 additions & 9 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@
return urlWithParams;
}

function updateSalah({ lat, long }) {
function updateSalah({ lat, lon }) {
var salahText = document.querySelector('#salah-status');
salahText.innerHTML = "Updating..";

var req = new XMLHttpRequest();
var apiURL = addParamsToUrl('http:https://api.aladhan.com/v1/calendar', {
latitude: lat,
longitude: long,
longitude: lon,
school: 1
});

Expand Down Expand Up @@ -160,8 +160,34 @@
* @param {{number}} lat the latitude of the geolocation.
* @param {{number}} long the longitude of the geolocation.
*/
function updateWeather({lat, long}) {
function updateWeather({lat, lon}) {
var weatherText = document.querySelector('#weather-text');

//make api request to some weather api using coordinates
var req = new XMLHttpRequest();
var apiURL = addParamsToUrl('http:https://api.openweathermap.org/data/2.5/weather', {
lat, lon,
appid: '42adc1f5752b2d26823d3349379d0339'
});

req.overrideMimeType("application/json");
req.open("GET", apiURL, false);
req.onreadystatechange = function () {
if (req.responseText) {
var res = JSON.parse(req.responseText)
var weather = res.weather[0].main;
var temp = convertTemp(res.main.temp);
weatherText.innerHTML = weather + ' ' + temp + '\u00B0F';
} else {
weatherText.innerHTML = ':(';
}
}
req.send();
}

function convertTemp(k = 0){
//Fahrenheit
return (1.8 * (k - 273) + 32).toFixed(1);
}

/**
Expand All @@ -185,7 +211,7 @@
}

/**
* Update weather and air pollution information.
* Update salah, weather information.
* If can't get location information, displays no GPS icon.
* @private
*/
Expand All @@ -194,12 +220,12 @@
function (pos) {
updateSalah({
lat: pos.coords.latitude,
long: pos.coords.longitude
lon: pos.coords.longitude
});
updateWeather({
lat: pos.coords.latitude,
lon: pos.coords.longitude
});
// updateWeather({
// lat: pos.coords.latitude,
// long: pos.coords.longitude
// });
}
);
}
Expand Down

0 comments on commit 5a4a3d2

Please sign in to comment.