Hi,
In case you want to display some feeds you can use something like this:
class PluginWikiWidgets(PluginWikiWidgets):
@staticmethod
def aggregator(feed, max_entries=5):
import gluon.contrib.feedparser as feedparser
d = feedparser.parse(feed)
title=d.channel.title,
link = d.channel.link,
description = d.channel.description,
strg='<a href='+link[0]+'>'+'<b>'+ title[0]+'</b></a><br/><br/>'
count=0;
for entry in d.entries:
created_on = request.now
strg+='<a href='+entry.link+'>'+entry.title+ ' - ' + entry.updated+ '</a><br/>'
strg+=entry.description+'<br/><br/>'
count+=1
if count >= int(max_entries):
break
return XML(strg)
It can be included in a page using the widget syntax:
``
name:aggregator
feed:http://rss.cbc.ca/lineup/topstories.xml
max_entries:4
``:widget
I got inspired from web2py planet, but that was just for creating feeds, whereas I needed just to display them. I hope that someone will find this useful and make it even better. It requires some beautifying work among others.
Bogdan
Edit:
I made some changes to make it slicker. For some reason the included jquery-ui lib did not work properly in the sense that the dialog was not following the mouse so I had to include one script form the google code site even though it is older. Maybe someone can figure out why 1.8.9 did not work. Anyway this si the include
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js">
the new plugin:
class PluginWikiWidgets(PluginWikiWidgets):
@staticmethod
def aggregator(feeds, max_entries=5):
import gluon.contrib.feedparser as feedparser
lfeeds = feeds.split(",")
#strg='<script>var divDia = document.createElement("div"); divDia.id ="dialog"; document.body.appendChild(divDia);</script>'
strg='''
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
<script>
var divDia = document.createElement("div");
divDia.id ="dialog";
document.body.appendChild(divDia);
var $dialog=$("#dialog").dialog({
autoOpen: false,
draggable: false,
resizable: false,
width: 500
});
</script>
'''
for feed in lfeeds:
d = feedparser.parse(feed)
title=d.channel.title,
link = d.channel.link,
description = d.channel.description,
strg+='<a href='+link[0]+'>'+'<b>'+ title[0]+'</b></a><br/>'
count=0;
for entry in d.entries:
created_on = request.now
strg+='<a rel=' + '"'+entry.description+'"' +' href='+entry.link+'>'+entry.title+ ' - ' + entry.updated+ '</a><br/>'
#strg+=entry.description+'<br/><br/>'
#strg+='<br/>'
strg+='''<script> $("a").mouseover(function () {
var msg = $(this).attr("rel");
if (msg) {
$dialog[0].innerHTML = msg;
$dialog.dialog("open");
$(".ui-dialog-titlebar").hide();
}
}).mousemove(function(event) {
$dialog.dialog("option", "position", {
my: "left top",
at: "right bottom",
of: event,
offset: "10 10"
});
}).mouseout(function(){
$dialog.dialog("close");
});
</script>'''
count+=1
if count >= int(max_entries):
break
strg+='<br/><br/>'
strg+="<br/>"
return XML(strg)
and it can be used with the following widget construction:
``
name:aggregator
feeds:http://rss.cbc.ca/lineup/topstories.xml,http://rss.cbc.ca/lineup/health.xml,http://www.dpreview.com/feeds/news.xml
max_entries:4
``:widget
Comments (1)
0
bogdanhlevca 13 years ago