Monday, November 08, 2010 at 12:05 AM.
system.verbs.builtins.radio.hotlist.reload
<<Changes:
<<3/5/02; 9:14:52 PM by JES
<<When reading the hotlist opml, call through tcp.httpClient, passing in true for flAcceptOpml, otherwise Radio we might get back opml rendered to html.
<<3/2/02; 3:36:58 PM by JES
<<Get the hotlist opml url from radio.data.cloudUrls.hotlistOpml, instead of using a locally hard-coded url.
<<12/5/01; 8:24:50 PM by JES
<<Commented out debugging code that was setting scratchpad.xstruct.
<<11/9/01; 9:56:53 PM by DW
<<Rewrite.
<<8/21/01; 12:10:01 AM by JES
<<Call radio.log.add instead of playlist.addToDailyLogDatabase.
<<2/26/01; 4:17:31 PM by PBS
<<Terminology: Hot List, not Hotlist.
<<2/15/01; 3:50:05 PM by PBS
<<Untaint the information gathered.
<<2/14/01; 5:22:53 PM by PBS
<<Load from an XML file written by the server.
<<Old code:
<<local (startticks = clock.ticks ())
<<myUserLandSuite.ourFavoriteSongsCom.init ()
<<local (flreload = true)
<<bundle //set flreload
<<local (day, month, year, hour, minute, second)
<<date.get (myUserLandData.ourFavoriteSongsCom.prefs.dateLastRead, @day, @month, @year, @hour, @minute, @second)
<<
<<local (daynow, monthnow, yearnow, hournow, minutenow, secondnow)
<<date.get (clock.now (), @daynow, @monthnow, @yearnow, @hournow, @minutenow, @secondnow)
<<
<<if (year != yearnow) or (month != monthnow) or (day != daynow) or (hour != hournow)
<<flreload = true
<<if flreload
<<bundle //fill myUserLandData.ourFavoriteSongsCom.users, sources
<<new (tabletype, @myUserLandData.ourFavoriteSongsCom.users)
<<new (tabletype, @myUserLandData.ourFavoriteSongsCom.sources)
<<local (xstruct)
<<xml.compile (tcp.httpreadurl (myUserLandData.ourFavoriteSongsCom.prefs.usersUrl), @xstruct)
<<local (adrusers = xml.getaddress (@xstruct, "users"))
<<local (userslist = xml.getaddresslist (adrusers, "user"), adrxuser)
<<local (adrtable = @myUserLandData.ourFavoriteSongsCom.users)
<<for adrxuser in userslist
<<local (adruser = @adrtable^.[xml.getAttributeValue (adrxuser, "email")])
<<new (tableType, adruser)
<<adruser^.name = xml.getAttributeValue (adrxuser, "name")
<<adruser^.url = xml.getAttributeValue (adrxuser, "url")
<<adruser^.userAgent = xml.getAttributeValue (adrxuser, "userAgent")
<<adruser^.whenLoggedOn = xml.getAttributeValue (adrxuser, "whenLoggedOn")
<<bundle //get the user's subscriptions, fold them into the sources table
<<try
<<local (xstruct)
<<xml.compile (tcp.httpReadUrl (adruser^.url + "/rss/misc/mySubscriptions.opml"), @xstruct)
<<local (adropml = xml.getAddress (@xstruct, "opml"))
<<local (adrbody = xml.getAddress (adropml, "body"))
<<local (outlinelist = xml.getAddressList (adrbody, "outline"))
<<local (adr, xmlurl, adrsource)
<<for adr in outlineList
<<xmlurl = xml.getAttributeValue (adr, "xmlUrl")
<<adrsource = @myUserLandData.ourFavoriteSongsCom.sources.[xmlurl]
<<if defined (adrsource^)
<<adrsource^.ctSubscribers++
<<else
<<adrsource^ = adr^.["/atts"]
<<adrsource^.ctSubscribers = 1
<<bundle //do the sorted index
<<local (adrsort = @myUserLandData.ourFavoriteSongsCom.sourcesSort, adrsource)
<<new (tabletype, adrsort)
<<for adrsource in @myUserLandData.ourFavoriteSongsCom.sources
<<adrsort^.[nameof (adrsource^)] = adrsource^.ctSubscribers
<<local (oldtarget = target.set (adrsort))
<<table.sortby ("Value")
<<target.set (oldtarget)
<<myUserLandData.ourFavoriteSongsCom.prefs.dateLastRead = clock.now ()
<<bundle //add an item to the daily log
<<if myUserLandData.prefs.flLogNewSources
<<local (htmltext = sizeof (myUserLandData.ourFavoriteSongsCom.sources) + " sources found.")
<<playlist.addToDailyLogDatabase ("Hotlist", htmltext, startticks)
<<bundle //clear the cache
<<new (tabletype, @myUserLandData.cache.ourFavoriteSongsCom)
<<1/23/01; 2:22:26 PM by DW
<<Clear the cache after reloading.
local (startticks = clock.ticks ());
local (adrdata = radio.hotlist.init ());
local (opmlurl = radio.data.cloudUrls.hotlistOpml);
local (xmlText);
bundle { //read the opml file
local (urlparts = string.urlSplit (opmlurl));
local (port = 80);
if urlparts[2] contains ":" {
port = number (string.nthfield (urlparts[2], ":", 2));
urlparts[2] = string.nthfield (urlparts[2], ":", 1)};
xmlText = string.httpResultSplit (tcp.httpClient (server:urlparts[2], port:port, path:urlparts[3], flAcceptOpml:true))};
local (xstruct);
xml.compile (xmlText, @xstruct);
<<scratchpad.xstruct = xstruct
local (adrtop100 = @adrdata^.top100);
new (tabletype, adrtop100);
local (adropml = xml.getAddress (@xstruct, "opml"));
local (adrbody = xml.getAddress (adropml, "body"));
local (outlinelist = xml.getAddressList (adrbody, "outline"));
local (adr, xmlurl, adrsource, ct = 1, adrtable);
for adr in outlineList {
adrtop100^.[string.padwithzeros (ct++, 3)] = adr^.["/atts"]};
radio.hotlist.clearCache ();
adrdata^.prefs.dateLastRead = clock.now ();
if user.radio.prefs.flLogHotlistReload {
local (htmltext = "Top-100 Most-Subscribed-To RSS <a href=\"" + opmlurl + "\">channels</a> loaded.");
radio.log.add ("Hot List", htmltext, startticks)}
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.