Monday, April 04, 2011 at 1:06 AM.
feedhoseSuite.newItemCallback
on newItemCallback (adrriveritem, adrfeed, adrxitem) {
<<Changes
<<12/8/10; 8:25:58 AM by DW
<<Put the section that gets the description in a try, since some feeds don't have descriptions on their items. This was causing the Hacker News hose not to wake up when an update came in.
<<9/29/10; 12:37:36 PM by DW
<<Adapt for hoses.
<<9/24/10; 4:19:13 AM by DW
<<Called when a new RSS item arrives.
local (adrdata = feedHoseSuite.init (), now = clock.now ());
adrdata^.server.stats.ctCallbackCalls++;
bundle { //check title, skip duplicates
local (adrtitle = @adrdata^.server.titles.[adrriveritem^.title]);
if defined (adrtitle^) {
adrdata^.server.stats.ctDuplicateTitles++;
return};
adrtitle^ = now};
adrdata^.server.stats.ctNewItemsLastScan++;
adrdata^.server.stats.lastNewItemFeed = nameof (adrfeed^);
on encode (s) {
if system.environment.isMac { //02/22/2001 JES: convert to Latin text
return (xml.entityEncode (latinToMac.macToLatin (s), true))}
else {
return (xml.entityEncode (s, true))}};
on deleteNamespaceElements (adrx) {
local (i, adrelement);
for i = sizeof (adrx^) downto 1 {
adrelement = @adrx^ [i];
if defined (adrelement^.["/atts"].namespace) {
delete (adrelement)}}};
on encodePcdata (adrx) {
local (adrelement);
for adrelement in adrx {
if typeof (adrelement^) == tabletype {
if defined (adrelement^.["/pcdata"]) {
adrelement^.["/pcdata"] = encode (adrelement^.["/pcdata"])}}}};
local (adrhose);
for adrhose in @adrdata^.server.hoses {
local (flcatch = false, hosename = nameof (adrhose^));
feedhosesuite.inithose (hosename); //make sure all fields are init'd
if adrhose^.prefs.enabled {
try {
if adrhose^.condition (adrriveritem, adrfeed, adrxitem) {
adrhose^.stats.ctItemsMatchCondition++;
adrhose^.stats.whenLastMatch = now;
flcatch = true}};
if flcatch {
local (adrday = mainresponder.calendar.getdayaddress (@adrhose^.calendar, now));
local (adritem = @adrday^.[string.padwithzeros (sizeof (adrday^) + 1, 5)]);
new (tabletype, adritem);
adritem^.riveritem = adrriveritem^;
<<adritem^.feedUrl = nameof (adrfeed^)
adritem^.xitem = adrxitem^;
deleteNamespaceElements (@adritem^.xitem);
encodePcdata (@adritem^.xitem); //the category element values aren't encoded properly
bundle { //process the description
try {
local (adrdescription = xml.getaddress (@adritem^.xitem, "description"));
local (s = searchengine.stripmarkup (adrdescription^));
if sizeof (s) > 280 {
s = string.mid (s, 1, 280);
while s [sizeof (s)] != " " {
s = string.delete (s, sizeof (s), 1)};
s = string.delete (s, sizeof (s), 1) + "..."};
adrdescription^ = s}};
<<bundle //temporary debugging code -- 12/8/10 by DW
<<log2.add ("FeedHose", "Wakeup", "Waking up threads waiting for the \"" + hosename + "\" hose.")
feedhoseSuite.wakeWaitingThreads (hosename)}}}};
bundle { //test code
newItemCallback (@config.feedHose.calendar.["2010"].["09"].["24"].["01115"].riveritem, @config.river2.feeds.["http://jobs.nytimes.com/careers/rss/jobs/?pbt=nytcategoryexecutive"], @config.feedHose.calendar.["2010"].["09"].["24"].["01115"].xitem)}
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.