Skip to content

Commit

Permalink
Add the newsfeed URL to config. Add weather icons to the forecast.
Browse files Browse the repository at this point in the history
  • Loading branch information
chmullig committed Aug 20, 2014
1 parent b8b32a4 commit eb7350f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
10 changes: 10 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!',
Expand Down
28 changes: 25 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -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'];
}
Expand All @@ -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)));

Expand All @@ -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) {
Expand Down

0 comments on commit eb7350f

Please sign in to comment.