Monday, November 08, 2010 at 12:00 AM.
scripting2Suite.oldstuff.getStories
on getStories (username, adrstories, maxstories=15) { <<Changes <<5/29/10; 12:53:04 PM by DW <<Rebuilt for scripting2.root. <<9/6/07; 7:12:56 PM by DW <<Core routine for building the home page, RSS feed, story list include. local (adrdata = scripting2Suite.initUser (username), adrday, archivedate, adrout, ix = 1); local (adrcal = scripting2Suite.loadOpmlArchive (username)); new (tabletype, adrstories); scripting2Suite.getMostRecentDay (username, @adrday, @archivedate); loop { if sizeof (adrstories^) >= maxstories { break}; if defined (adrday^.f) { //there is an outline for that day scripting2Suite.initArchiveDay (adrday); if not defined (adrday^.xstruct) { xml.compile (adrday^.opml, @adrday^.xstruct)}; local (adropml = xml.getaddress (@adrday^.xstruct, "opml")); local (adrbody = xml.getaddress (adropml, "body")); for adrout in adrbody { if nameof (adrout^) endswith "outline" { local (adrstory = @adrstories^.[string.padwithzeros (ix++, 4)], enclosureUrl = ""); new (tabletype, adrstory); adrstory^.title = adrout^.["/atts"].text; bundle { //set when try { adrstory^.when = date (adrout^.["/atts"].created)} else { adrstory^.when = archivedate}}; bundle { //get the story body local (adrsubout, s = ""); for adrsubout in adrout { if nameof (adrsubout^) endswith "outline" { s = s + xml.entitydecode (adrsubout^.["/atts"].text, flAlphaEntities:true) + "<br><br>\r"; try { //3/5/08 by DW, set enclosureUrl if adrsubout^.["/atts"].type == "link" { enclosureUrl = adrsubout^.["/atts"].url}}}}; adrstory^.body = s}; bundle { //set the enclosure, 3/5/08 by DW try { if enclosureUrl != "" { local (urllist = string.urlsplit (enclosureUrl), headheaders, t); local (s = tcp.httpClient ("HEAD", server:urllist [2], path:urllist [3], timeOutTicks:60*30, flmessages:false, ctFollowRedirects:5)); new (tabletype, @headheaders); webserver.util.parseHeaders (s, @headheaders); scratchpad.headheaders = headheaders; new (tabletype, @t); t.url = enclosureUrl; t.length = headheaders.["Content-length"]; t.type = headheaders.["Content-Type"]; adrstory^.enclosure = t}}}; <<add ("<enclosure url=\"" + url + "\" length=\"" + headheaders.["Content-length"] + "\" type=\"" + headheaders.["Content-Type"] + "\" />") if sizeof (adrstories^) >= maxstories { break}}}}; archivedate = date.yesterday (archivedate); adrday = mainresponder.calendar.getDayAddress (adrcal, archivedate, false)}}; bundle { //test code local (tc = clock.ticks ()); getStories ("davewiner", @scratchpad.recentStories, 10); dialog.alert (clock.ticks () - tc); edit (@scratchpad.recentStories)}
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.