Monday, November 08, 2010 at 12:00 AM.

scripting2Suite.utilities.createInputFolder

<<Changes
	<<6/2/10; 4:28:10 PM by DW
		<<This script loops over a folder structure created by the old scriptingNews.root, where each file contains a day's worth of blog posts. The new format requires that each archived post be in its own OPML file. That's the kind of folder we create. 
local (sourcefolder = "Macintosh HD:Users:davewiner:Desktop:intoScripting2:dailyArchive:", f);
local (destfolder = "Macintosh HD:Users:davewiner:Desktop:intoScripting2:storyArchive:", ct=1, moddate);
on hassubs (adrx) { //return true if the outline node has sub-outlines
	local (adr);
	for adr in adrx {
		if nameof (adr^) endswith "outline" { //contains at least one sub
			return (true)}};
	return (false)};
fileloop (f in sourcefolder, infinity) {
	if f endswith ".opml" {
		local (s = file.readwholefile (f), xstruct, i);
		msg (f);
		xml.compile (s, @xstruct);
		local (adropml = xml.getaddress (@xstruct, "opml"));
		local (adrbody = xml.getaddress (adropml, "body"));
		for i = sizeof (adrbody^) downto 1 {
			adr = @adrbody^ [i];
			if (nameof (adr^) endswith "outline") and hassubs (adr) {
				local (xstructcopy = xstruct);
				local (adropmlcopy = xml.getaddress (@xstructcopy, "opml"));
				local (adrbodycopy = xml.getaddress (adropmlcopy, "body"));
				bundle { //get the date, if we fail, do it gracefully
					try {
						 moddate = date (xml.getattributevalue (adr, "created"))}
					else {
						moddate = file.modified (f);
						adr^.["/atts"].created = moddate}}; //very important that every story have a created attribute
						<<edit (@adr^.["/atts"])
				new (tabletype, adrbodycopy);
				adrbodycopy^.[nameof (adr^)] = adr^;
				local (fstory = destfolder + string.padwithzeros (ct++, 4) + ".opml");
				file.surefilepath (fstory);
				file.writewholefile (fstory, xml.decompile (@xstructcopy));
				file.setcreated (fstory, moddate);
				file.setmodified (fstory, moddate)}}}}



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.