Düber
Executive Member
- Joined
- May 17, 2018
- Messages
- 7,032
- Reaction score
- 10,725
I have a notice board setup at home. It has behaved itself perfectly for a long while now, but yesterday it stopped telling us the news. I told my wife the Government has heard all her comment's and shut us down.
But it turns out I was wrong.
"Important EOL Notice: As of Thursday, Jan. 3, 2019, the YQL service at query.yahooapis.com will be retired. This will impact users of datatables.org as well as developers who creates features using this YQL service. To continue using our free Yahoo Weather APIs, use https://weather-ydn-yql.media.yahoo.com/forecastrss as your new API endpoint. Contact [email protected] for credentials to onboard to this free Yahoo Weather API service. Other YQL based services that use query.yahooapis.com will no longer operate."
Now that is awesome!
I fear to say that my coding abilities are a little less than what would be bad.
It is a webserver running on a Orange pi with LAMP, with the majority of the code lifted from here
https://github.com/MichMich/MagicMirror
but an older version.
Essentially it is a webpage with weather, a calendar, clock... etc.
The RSS feeds and age of feeds to display are listed in a config.js file and the code below is the relevant section in the main.js file, it then displays the news feed titles at the bottom of the page one at a time from the various feeds.
Searching throughout the day I have found,
https://stackoverflow.com/questions/246577/can-i-serve-rss-in-json
and
as possible solutions.
It is starting to feel like I'm trying to reinvent the wheel with the spokes on the outside.
I don't want this to be a - Try this.....Not working.....try this..., thread, but some advice and guiding in the right approach would be very helpful.
TIA
My head hurts, I'm cross eyed and rather frustrated at my lack of knowledge!
But it turns out I was wrong.
"Important EOL Notice: As of Thursday, Jan. 3, 2019, the YQL service at query.yahooapis.com will be retired. This will impact users of datatables.org as well as developers who creates features using this YQL service. To continue using our free Yahoo Weather APIs, use https://weather-ydn-yql.media.yahoo.com/forecastrss as your new API endpoint. Contact [email protected] for credentials to onboard to this free Yahoo Weather API service. Other YQL based services that use query.yahooapis.com will no longer operate."
Now that is awesome!
I fear to say that my coding abilities are a little less than what would be bad.
It is a webserver running on a Orange pi with LAMP, with the majority of the code lifted from here
https://github.com/MichMich/MagicMirror
but an older version.
Essentially it is a webpage with weather, a calendar, clock... etc.
The RSS feeds and age of feeds to display are listed in a config.js file and the code below is the relevant section in the main.js file, it then displays the news feed titles at the bottom of the page one at a time from the various feeds.
Searching throughout the day I have found,
https://stackoverflow.com/questions/246577/can-i-serve-rss-in-json
and
as possible solutions.
It is starting to feel like I'm trying to reinvent the wheel with the spokes on the outside.
I don't want this to be a - Try this.....Not working.....try this..., thread, but some advice and guiding in the right approach would be very helpful.
JavaScript:
// RSS Feed Display. Updates every 5 minutes.
function fetchNews() {
// Yahoow Query Language implementation borrowed from jquery.feedToJSON.js by [email protected]
var yqlURL = 'http://query.yahooapis.com/v1/public/yql'; // yql itself
var yqlQS = '?format=json&callback=?&q=select%20*%20from%20rss%20where%20url%3D'; // yql query string
var cachebuster = new Date().getTime(); // yql caches feeds, so we change the feed url each time
var index = 0;
// Loop through the feed URLs
for( var key in feedURLs ) {
var url = yqlURL + yqlQS + "'" + encodeURIComponent( feedURLs[key] ) + "'" + "&_nocache=" + cachebuster;
fetchNewsForURL( index++, url );
}
// Update again in 5 minutes
setTimeout( fetchNews, 300000 );
};
fetchNews();
// Actually get a feed. The function exists just so we can fake passing
// extra arguments to getJSON().
function fetchNewsForURL( index, url )
{
$.getJSON( url, function(jsonRSS, textStatus) {
if( jsonRSS.query.results != null ) {
// Success; get the list of articles
var oldestDate = moment().subtract( feedMaxAge.days, "days" ).subtract( feedMaxAge.hours, "hours" );
var stories = [];
for (var i in jsonRSS.query.results.item) {
// Skip articles older than a certain time
// pubDate string is "Tue, 05 Jul 2016 14:25:29 -0400", so we decode that
var storyDate = moment( jsonRSS.query.results.item[i].pubDate, "ddd, DD MMM YYYY HH:mm:ss Z" );
if( oldestDate.diff( storyDate ) < 0 ) {
stories.push( jsonRSS.query.results.item[i].title );
}
}
news[ index ] = stories;
// Update the "last updated" information with a count of all stories from all feeds
var newsCountTotal = 0;
for( var i=0; i < news.length; i++ ) {
newsCountTotal += news[i].length;
}
$('.luRSS').updateWithText('rss (' + newsCountTotal + ' articles/' + news.length + ' feeds): ' + moment().format('h:mm a ddd MMM D YYYY'), 1000);
}
});
}
(function showNews() {
var initialFeed = newsFeedIndex;
if( news.length == 0 ) {
// No news; nothing to do
return;
}
// Find the next story
for( var i=0; i < news.length+1; i++ ) {
var newsFeed = news[ newsFeedIndex ];
// Fix undefined entries
if( newsFeed === undefined )
continue;
// Skip empty feeds
if( newsFeed.length == 0 ) {
if( ++newsFeedIndex == news.length )
newsFeedIndex = 0;
newsStoryIndex = 0;
continue;
}
// Check for the last story in the feed
if( newsStoryIndex >= newsFeed.length ) { // newsStoryIndex can become greater than the array if the story count updated behind the scenes
newsStoryIndex = 0;
if( ++newsFeedIndex >= news.length ) {
newsFeedIndex = 0;
continue;
}
}
}
if( news[ newsFeedIndex ].length == 0 ) {
// No stories
setTimeout( showNews, 1000 );
return;
}
// Get the title text
var i = 0;
for( var key in feedURLs ) {
if( i == newsFeedIndex )
break;
i++;
}
$('.newsTitle').updateWithTextForce(key + '<hr width="20%" style="opacity:0.3">', 2000, true);
// Draw feed/story dots
var newsDots = ""
for( i=0; i < news.length; i++ ) {
if( i == newsFeedIndex )
newsDots += '<span class="dimmed">•</span>'
else
newsDots += '<span class="xxdimmed">•</span>'
}
newsDots += " ";
for( i=0; i < news[ newsFeedIndex ].length; i++ ) {
if( i == newsStoryIndex )
newsDots += '<span class="dimmed">•</span>'
else
newsDots += '<span class="xxdimmed">•</span>'
}
$('.newsDots').updateWithTextForce(newsDots, 2000, true);
// Get the story text
var newsFeed = news[ newsFeedIndex ];
newsStory = newsFeed[ newsStoryIndex ];
var nextTimeout = 1000; // Used in error cases where newsStory is undefined for some reason
if( typeof newsStory != 'undefined') {
$('.news').updateWithText( newsStory, 2000 );
nextTimeout = 5500 + (newsStory.length * 20);
}
// Set up for the next story
newsStoryIndex++;
setTimeout( showNews, nextTimeout ); // Length of the headline modifies how long it stays on screen
})();
});
TIA
My head hurts, I'm cross eyed and rather frustrated at my lack of knowledge!

