Saturday, April 02, 2011 at 9:18 PM.

feedhoseSuite.client.write

on write (hosename) {
	<<Changes
		<<9/29/10; 2:52:21 PM by DW
			<<Added hosename param.
	local (adrdata = feedHoseSuite.init (), maxct = 250, ct = 0, htmltext = "", indentlevel = 0, now = clock.now (), feedtitlecolor = "gray");
	local (adrhose = feedhosesuite.client.inithose (hosename));
	adrhose^.stats.ctWrites++;
	adrhose^.stats.whenLastWrite = now;
	bundle { //generate htmltext
		local (lastfeedtitle = "");
		on add (s) {
			htmltext = htmltext + string.filledstring ("\t", indentlevel) + s + "\r"};
		on decode (s) {
			return (xml.entitydecode (s, flAlphaEntities:true, flDecodeHexEntities:true))};
		on visit (adritem) {
			local (title = decode (xml.getvalue (adritem, "title")), link);
			<<scratchpad.adritem = adritem
			bundle { //set link
				if not defined (adritem^.link) {
					adritem^.link = tcp.httpderef (decode (xml.getvalue (adritem, "link")))};
				link = adritem^.link};
			try {
				local (description = string.trimwhitespace (decode (xml.getvalue (adritem, "description"))));
				bundle { //fix up title
					local (s = string.trimwhitespace (string.addPeriodToSentence (title)));
					local (chlast = s [sizeof (s)], when);
					s = string.delete (s, sizeof (s), 1);
					local (feedTitle = decode (xml.getvalue (adritem, "feedTitle")));
					feedTitle = string.trimwhitespace (string.nthfield (feedTitle, ">", 2));
					feedTitle = string.replace (feedTitle, "Most Recent Headlines", "Realtime Feed");
					local (feedUrl = decode (xml.getvalue (adritem, "feedUrl")));
					local (feedlink = "<font size=\"-1\"><a href=\"" + feedurl + "\">" + feedtitle + "</a>.</font>");
					<<bundle //add feed title, if it changed
						<<if feedtitle contains "Electronista"
							<<msg ("break")
						<<if feedTitle != lastfeedtitle
							<<local (s = string.replace (feedtitle, "NYT > ", ""))
							<<add ("<h4>" + s + " -- " + date.viewDate (timecreated (adritem)) + "</h4>")
							<<lastfeedtitle = feedTitle
					bundle { //set when
						when = timecreated (adritem);
						when = date.timestring (when, false) - " ";
						when = "<font size=\"-1\">" + when + ".</font>"};
					<<add ("<tr>"); indentlevel++
					<<add ("<td valign=\"top\">" + when + "</td>")
					<<add ("<td valign=\"top\"><a href=\"" + link + "\">" + s + "</a>" + chlast + " " + description + "</td>")
					<<add ("</tr>"); indentlevel--
					add ("<p><a href=\"" + link + "\">" + s + "</a>" + chlast + " " + description + " " + when + " " + feedlink + "</p>")};
				return (++ct < maxct)}
			else {
				add ("<p>" + tryerror + "</p>")}};
		<<add ("<p>" + clock.now () + "</p>")
		<<add ("<table cellspacing=\"7\" cellpadding=\"0\">"); indentlevel++
		mainresponder.calendar.visitReverseChronologic (@adrhose^.calendar, @visit)};
		<<add ("</table>"); indentlevel--
	bundle { //flow through template
		local (t);
		new (tabletype, @t);
		t.title = adrhose^.prefs.title;
		t.programName = "FeedHose tool v" + feedhoseInfo.version;
		t.bodytext = htmltext;
		t.now = now;
		htmltext = string.multiplereplaceall (string (feedhoseSuite.client.template), @t, false, "<%", "%>")};
	bundle { //write to the file
		local (f = adrhose^.prefs.fHtml);
		if sizeof (f) > 0 { //2/12/11 by DW
			file.surefilepath (f);
			file.writewholefile (f, htmltext)}};
	return (htmltext)};
bundle { //test code
	write ("tech")}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.