Add the newsfeed URL to config. Add weather icons to the forecast.

This commit is contained in:
Chris Mulligan 2014-08-20 10:42:02 -04:00
parent b8b32a449c
commit eb7350fb52
3 changed files with 43 additions and 5 deletions

View File

@ -134,6 +134,16 @@ body, html {
margin-right: 10px;
}
.icon-small
{
position: relative;
display: inline-block;
font-size: 20px;
padding-left: 10px;
padding-right: -10px;
font-weight: 100;
}
.time .sec {
font-size: 25px;
color: #666;

View File

@ -4,12 +4,18 @@ var lang = window.navigator.language;
//var lang = 'en';
//change weather params here:
//units: metric or imperial
var weatherParams = {
'q':'Baarn,Netherlands',
'units':'metric',
'q':'New York, NY',
'units':'imperial',
'lang':lang
};
//var feed = 'http://feeds.nos.nl/nosjournaal?format=rss';
//var feed = 'http://www.nu.nl/feeds/rss/achterklap.rss';
//var feed = 'http://www.nu.nl/feeds/rss/opmerkelijk.rss';
var feed = 'http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml';
// compliments:
var compliments = [
'Hey, handsome!',

View File

@ -249,6 +249,26 @@ jQuery(document).ready(function($) {
(function updateWeatherForecast()
{
var iconTable = {
'01d':'wi-day-sunny',
'02d':'wi-day-cloudy',
'03d':'wi-cloudy',
'04d':'wi-cloudy-windy',
'09d':'wi-showers',
'10d':'wi-rain',
'11d':'wi-thunderstorm',
'13d':'wi-snow',
'50d':'wi-fog',
'01n':'wi-night-clear',
'02n':'wi-night-cloudy',
'03n':'wi-night-cloudy',
'04n':'wi-night-cloudy',
'09n':'wi-night-showers',
'10n':'wi-night-rain',
'11n':'wi-night-thunderstorm',
'13n':'wi-night-snow',
'50n':'wi-night-alt-cloudy-windy'
}
$.getJSON('http://api.openweathermap.org/data/2.5/forecast', weatherParams, function(json, textStatus) {
var forecastData = {};
@ -260,10 +280,12 @@ jQuery(document).ready(function($) {
if (forecastData[dateKey] == undefined) {
forecastData[dateKey] = {
'timestamp':forecast.dt * 1000,
'icon':forecast.weather[0].icon,
'temp_min':forecast.main.temp,
'temp_max':forecast.main.temp
};
} else {
forecastData[dateKey]['icon'] = forecast.weather[0].icon;
forecastData[dateKey]['temp_min'] = (forecast.main.temp < forecastData[dateKey]['temp_min']) ? forecast.main.temp : forecastData[dateKey]['temp_min'];
forecastData[dateKey]['temp_max'] = (forecast.main.temp > forecastData[dateKey]['temp_max']) ? forecast.main.temp : forecastData[dateKey]['temp_max'];
}
@ -275,10 +297,12 @@ jQuery(document).ready(function($) {
var opacity = 1;
for (var i in forecastData) {
var forecast = forecastData[i];
var iconClass = iconTable[forecast.icon];
var dt = new Date(forecast.timestamp);
var row = $('<tr />').css('opacity', opacity);
row.append($('<td/>').addClass('day').html(moment.weekdaysShort(dt.getDay())));
row.append($('<td/>').addClass('icon-small').addClass(iconClass));
row.append($('<td/>').addClass('temp-max').html(roundVal(forecast.temp_max)));
row.append($('<td/>').addClass('temp-min').html(roundVal(forecast.temp_min)));
@ -297,9 +321,7 @@ jQuery(document).ready(function($) {
(function fetchNews() {
$.feedToJson({
feed:'http://feeds.nos.nl/nosjournaal?format=rss',
//feed:'http://www.nu.nl/feeds/rss/achterklap.rss',
//feed:'http://www.nu.nl/feeds/rss/opmerkelijk.rss',
feed: feed,
success: function(data){
news = [];
for (var i in data.item) {