Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weather Module #32

Merged
merged 1 commit into from
Mar 17, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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