Skip to content

Commit

Permalink
Merge pull request #32 from JaredCubilla/gh-pages
Browse files Browse the repository at this point in the history
Weather Module
  • Loading branch information
cherche committed Mar 17, 2016
2 parents 1afe653 + 682adef commit aa899d1
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions assets/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ $(function () {
theme: '',
// If sound is on
sound: false,
// Location settings (optional, only for specific modules)
location: {
'lat': 0,
'lon': 0,
'country': '',
'countryCode': '',
'city': ''
},
// Module settings
modules: {
'random': false,
'entertainment': false
'entertainment': false,
'weather': false
}
};
// Evaluation of memory cookie
Expand Down Expand Up @@ -94,7 +103,9 @@ $(function () {
if (settings(y)) {
if (random(y)) {
if (entertainment(y)) {
core(y);
if (weather(y)) {
core(y);
}
}
}
}
Expand Down Expand Up @@ -268,6 +279,41 @@ $(function () {
return true;
}
}

// [Optional] Entertainment module
function weather (y) {
if (memory.modules.weather) {
if (y === 'what is the weather' || y === 'what is the weather like' || y === 'what is the weather like today') {
say('Here\'s what we could find:');
$.getJSON('http://freegeoip.net/json/', function(d) {
memory.location.lat = d.latitude;
memory.location.lon = d.longitude;
memory.location.country = d.country_name;
memory.location.countryCode = d.country_code;
memory.location.city = d.city;

$.getJSON('http://api.openweathermap.org/data/2.5/weather?lat=' + memory.location.lat + '&lon=' + memory.location.lon + '&units=metric&appid=54c09e3b86f7c45f6629c50b2257c22f', function(d) {
$('<div class="box"><h3 class="title">' + memory.location.city + ', ' + memory.location.country + '</h3><div style="background-image:url(\'http://openweathermap.org/img/w/' + d.weather[0].icon + '.png\'); width:50px; height:50px; display: inline-block;" alt="' + d.weather[0].main + '"></div><h1 class="title" style="display:inline-block; padding-left:0.2vw;">' + d.main.temp + 'C°</h1><p><span style="text-transform:capitalize;font-weight:500;">' + d.weather[0].description + '</span><br>Wind Speed: ' + d.wind.speed + 'm/s<br>Humidity: ' + d.main.humidity + '%</p></div>').appendTo('#conversation-box').fadeIn('slow');
});
});
} else if (y === 'what is the temperature' || y === 'how hot is it today' || y === 'how cold is it today') {
$.getJSON('http://freegeoip.net/json/', function(d) {
memory.location.lat = d.latitude;
memory.location.lon = d.longitude;
memory.location.country = d.country_name;
memory.location.countryCode = d.country_code;
memory.location.city = d.city;

$.getJSON('http://api.openweathermap.org/data/2.5/weather?lat=' + memory.location.lat + '&lon=' + memory.location.lon + '&units=metric&appid=54c09e3b86f7c45f6629c50b2257c22f', function(d) {
say('The temperature right now in <b>' + memory.location.city + '</b> is <b>' + d.main.temp+ 'C°</b>.');
});
});
}
} else {
return true;
}
}

// [Optional] Entertainment module
function entertainment (y) {
if (memory.modules.entertainment) {
Expand Down

0 comments on commit aa899d1

Please sign in to comment.