'allo. I've attached a renderer for RSS feeds. It's still pretty rough, but I'm hoping to get some feedback on how the RSS feeds should be displayed. Thanks! -- Kevin Godby <godbyk yahoo com>
--- dashboard-pristine/backends/RSSBackend.cs 2004-02-20 16:14:26.000000000 -0600
+++ dashboard/backends/RSSBackend.cs 2004-02-23 12:57:50.000000000 -0600
@@ -34,6 +34,9 @@
protected override ArrayList ProcessClueSimple (Clue clue)
{
+ DateTime StartExec = DateTime.Now;
+ Console.WriteLine ("..Backend: RSS.. starting at {0}", StartExec);
+
ArrayList matches = new ArrayList();
XmlDocument xml = this.GetRSS (clue.Text);
@@ -113,9 +116,15 @@
if (guid != null)
match ["GUID"] = guid;
+ // Added by godbyk -- we'll see if this is all I need to do. <crosses fingers>
+ match ["PubDate"] = item.PubDate;
+
matches.Add (match);
}
+ Console.WriteLine ("..Backend: RSS.. stopping at {0}", DateTime.Now);
+ Console.WriteLine ("..Backend: RSS.. elapsed time {0}", DateTime.Now - StartExec);
+
return matches;
}
@@ -148,7 +157,6 @@
ArrayList items = new ArrayList ();
XmlNodeList items_xml = xml.SelectNodes ("//item");
foreach (XmlNode item_xml in items_xml) {
-Console.WriteLine("1");
string guid = this.GetXmlNodeText (item_xml, "guid");
string link = this.GetXmlNodeText (item_xml, "link");
string title = this.GetXmlNodeText (item_xml, "title");
//
// GNOME Dashboard
//
// RSSMatchRenderer.cs: Knows how to render RSS matches.
//
// Author:
// Kevin Godby <godbyk yahoo com>
//
using System;
using System.Collections;
using System.Xml;
using System.IO;
namespace Dashboard {
class RSSMatchRenderer : MatchRenderer {
public int MaxEntries = -1; // The max number of entries to show (per feed)
public int MatchNumber = 0; // This is used later on..
public override void Startup ()
{
Type = "RSS";
}
public override string HTMLRenderMatches (ArrayList matches)
{
DateTime StartExec = DateTime.Now;
Console.WriteLine ("..Renderer: RSS.. starting at {0}", StartExec);
StringWriter sw = new StringWriter ();
XmlWriter xw = new XmlTextWriter (sw);
xw.WriteStartElement ("div"); // Start the rss results block
// xw.WriteElementString ("u", "RSS Feed"); // Print the title
// xw.WriteStartElement ("br");
// xw.WriteEndElement (); // br
ArrayList Titles = new ArrayList ();
// Get all the unique rss feed titles
foreach (Match m in matches) {
string Title = Convert.ToString (m ["Title"]);
if (!Titles.Contains (Title))
Titles.Add (Title);
}
// Let's display some output already!
foreach (string title in Titles)
HTMLRenderSingleRSSTitle (title, matches, xw);
xw.WriteEndElement (); // End rss results block
xw.Close ();
Console.WriteLine ("..Renderer: RSS.. stopping at {0}", DateTime.Now);
Console.WriteLine ("..Renderer: RSS.. elapsed time {0}", DateTime.Now - StartExec);
return sw.ToString ();
}
private void HTMLRenderSingleRSSTitle (string Title, ArrayList matches, XmlWriter xw)
{
string Icon = "internal:rss.png";
// xw.WriteStartElement ("img"); // rss icon
// xw.WriteAttributeString ("src", Icon);
xw.WriteStartElement ("font"); // Make the font smaller to fit window width
xw.WriteAttributeString ("size", "+0");
xw.WriteString (" " + Title + " (RSS feed)");
xw.WriteStartElement ("br");
xw.WriteEndElement (); // br
xw.WriteStartElement ("ul");
MatchNumber = 0;
int NumEntries = 0;
foreach (Match m in matches) {
NumEntries++;
if ((NumEntries <= MaxEntries) || (MaxEntries == 0) || (MaxEntries == -1))
HTMLRenderSingleRSSItem (m, xw);
}
xw.WriteEndElement (); // ul
xw.WriteEndElement (); // font
}
private void HTMLRenderSingleRSSItem (Match m, XmlWriter xw)
{
string Title = Convert.ToString (m ["Title"]);
string Description = Convert.ToString (m ["Description"]);
string ItemTitle = Convert.ToString (m ["ItemTitle"]);
string Weblink = Convert.ToString (m ["Weblink"]);
string GUID = Convert.ToString (m ["GUID"]);
DateTime PubDate = DateTime.Parse (Convert.ToString (m ["PubDate"]));
string Icon = "internal:rss.png";
// Console.WriteLine ("..Renderer: RSS.. PubDate = {0}", PubDate);
// Grab first sentence from Description
string BareDescription = StripHTML (Description);
string Sentence = BareDescription.Substring (0, BareDescription.IndexOf (".") + 1) + " . .";
xw.WriteStartElement ("li");
xw.WriteStartElement ("a");
xw.WriteAttributeString ("href", Weblink);
xw.WriteAttributeString ("style", "text-decoration: none;");
xw.WriteString (ItemTitle);
xw.WriteEndElement (); // a href
// If it's an entry from today, or the most recent entry show a short intro
if ((PubDate == DateTime.Today) || (MatchNumber == 0)) {
xw.WriteStartElement ("br");
xw.WriteEndElement (); // br
xw.WriteStartElement ("font");
xw.WriteAttributeString ("size", "-1");
xw.WriteAttributeString ("color", "#666666");
xw.WriteRaw (Sentence);
xw.WriteEndElement (); // font
xw.WriteStartElement ("br");
xw.WriteEndElement (); // br
}
xw.WriteEndElement (); // li
MatchNumber++;
}
private string StripHTML (string myhtml) {
// I'm sure there's a better regex or builtin function for this..
System.Text.RegularExpressions.Regex tags = new System.Text.RegularExpressions.Regex(@"<[^>]+>|</[^>]+>");
return tags.Replace(myhtml, "");
}
}
}
Attachment:
rss-renderer.png
Description: PNG image