Monday, April 04, 2011 at 1:05 AM.
feedhoseSuite.getBackItems
on getBackItems (hosename, seed, adrreturnx, startticks = clock.ticks (), adrctitems = nil) { <<Changes <<12/7/10; 5:06:33 PM by DW <<Add optional parameter, adrctitems. <<12/2/10; 4:29:57 AM by DW <<If the seed points to an item we don't have, it's either a bad seed or an old one. In either case, we can't do anything with it, so we return an empty items table. <<9/29/10; 12:18:50 PM by DW <<Add hosename parameter. <<9/25/10; 6:59:47 PM by DW <<Return true if there are actually some items in the table, false otherwise. <<9/25/10; 2:45:48 PM by DW <<seed is of the form 2010-09-24-00250, which indicates the 250th item on 9/24/10. <<We return a table filled with all the items that have posted since then. local (adrdata = feedHoseSuite.init (), items, adrlastitem); local (adrhose = feedhosesuite.inithose (hosename)); local (adrcal = @adrhose^.calendar, maxhoseitems = adrdata^.server.prefs.maxHoseItems); 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))}}; bundle { //fill items table local (adrseed, year, month, day, itemname); new (tabletype, @items); on visit (adritem) { if adritem == adrseed { //we've already seen this one return (false)}; local (adrx = xml.addtable (@items, "item")); adrx^ = adritem^.xitem; bundle { //add feed info local (feedurl = adritem^.riveritem.feedurl); xml.addvalue (adrx, "feedUrl", feedurl); xml.addvalue (adrx, "feedTitle", config.river2.feeds.[feedurl].feedinfo.title); xml.addvalue (adrx, "feedLink", config.river2.feeds.[feedurl].feedinfo.link)}; bundle { //add thumbnail, if present, 10/14/10 by DW try { if defined (adritem^.riveritem.thumbnail) { xml.addvalue (adrx, "thumbUrl", adritem^.riveritem.thumbnail.url); xml.addvalue (adrx, "thumbWidth", adritem^.riveritem.thumbnail.width); xml.addvalue (adrx, "thumbHeight", adritem^.riveritem.thumbnail.height)}}}; if sizeof (items) >= maxhoseitems { return (false)}; return (true)}; //keep visiting bundle { //set year, month, day, itemname year = string.nthfield (seed, "-", 1); month = string.nthfield (seed, "-", 2); day = string.nthfield (seed, "-", 3); itemname = string.nthfield (seed, "-", 4)}; bundle { //set adrseed, if it worked (the seed is good), try to fill the items table try { adrseed = @adrcal^.[year].[month].[day].[itemname]; mainresponder.calendar.visitReverseChronologic (adrcal, @visit)}}}; <<bundle //set adrlastitem <<local (nomad = adrcal) <<nomad = @nomad^ [sizeof (nomad^)] //last year <<nomad = @nomad^ [sizeof (nomad^)] //last month <<nomad = @nomad^ [sizeof (nomad^)] //last day <<nomad = @nomad^ [sizeof (nomad^)] //last item <<adrlastitem = nomad bundle { //re-order items table local (adr, ix = sizeof (items), name); for adr in @items { name = string.padwithzeros (ix--, 8) + "\titem"; table.rename (adr, name)}}; <<target.set (@items) <<table.sortby ("Name") <<scratchpad.items = items bundle { //build the return table, an "feedHose" wrapper, containing the items local (adrfeedhose, adritems, adrmetadata); new (tabletype, adrreturnx); adrfeedhose = xml.addtable (adrreturnx, "feedHose"); if sizeof (items) > 0 { adritems = xml.addtable (adrfeedhose, "items"); adritems^ = items}; adrmetadata = xml.addtable (adrfeedhose, "metadata"); xml.addvalue (adrmetadata, "seed", feedhoseSuite.getCurrentSeed (hosename)); bundle { //add a secs element <<local (s = string (double (clock.ticks () - startticks) / 60)) <<local (lod = string.nthfield (s, ".", 1)) <<local (rod = string.nthfield (s, ".", 2) + "00") <<if sizeof (rod) > 3 <<rod = string.mid (rod, 1, 3) <<xml.addvalue (adrmetadata, "secs", lod + "." + rod) xml.addvalue (adrmetadata, "secs", string.formatdouble (double (clock.ticks () - startticks) / 60))}}; bundle { //set adrctitems^, 12/7/10 by DW if adrctitems != nil { adrctitems^ = sizeof (items)}}; return (sizeof (items) > 0)}; bundle { //test code getBackItems ("nytimes", "2010-12-01-00033", @scratchpad.items)}
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.