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

system.verbs.builtins.radio.backup.backupOneMonth

on backupOneMonth (year, month, adrblog = radio.weblog.init ()) {
	<<Changes
		<<3/13/03; 12:47:23 PM by JES
			<<Convert wptext objects to strings before attempting to do entity-encoding.
		<<11/27/02; 8:53:32 PM by JES
			<<Add sourceTime in a try block in case there's some bad data in the post table.
		<<11/26/02; 3:39:55 PM by JES
			<<Use file.writeWholeFile instead of file.writeTextFile to save the RSS file. Fixes a problem on MacOS where the file would mistakenly be re-written even though nothing in the month has changed.
		<<11/14/02; 12:55:25 PM by DW
			<<Optimize so we only write the file if it changed. This means that we must not write a <lastBuildDate> or a comment at the head of the file indicating when it was last built because these will be seen as a change. If these ever are brought back, you'll be upstreaming a lot more than you have to every time you do a full backup.
		<<11/14/02; 11:31:23 AM by DW
			<<Add support for radioWeblogPost, implement <radioWeblogPost:flNotOnHomePage>.
		<<11/12/02; 3:47:10 PM by DW
			<<Created.
	local (pc = file.getpathchar ());
	local (f = user.radio.backup.prefs.folder + "posts" + pc + year + pc + string.padwithzeros (month, 2) + ".xml");
	local (xmltext = "", indentlevel = 0);
	on add (s) {
		xmltext = xmltext + (string.filledstring ("\t", indentlevel) + s + "\r\n");};
	on encode (s) {
		if system.environment.isMac { //02/22/2001 JES: convert to Latin text
			return (xml.entityEncode (latinToMac.macToLatin (string (s)), true))}
		else {
			return (xml.entityEncode (string (s), true))}};
	add ("<?xml version=\"1.0\"?>");
	<<add ("<!-- RSS generated by " + frontier.getProgramName () + " on " + clock.now () + " -->")
	add ("<rss version=\"2.0\" xmlns:radioWeblogPost=\"http://backend.userland.com/radioWeblogPostModule\">"); indentlevel++;
	add ("<channel>"); indentlevel++;
	add ("<title>" + encode (adrblog^.prefs.title) + "</title>");
	add ("<link>" + encode (radio.weblog.getUrl (adrblog)) + "</link>");
	add ("<description>" + encode (adrblog^.prefs.description) + "</description>");
	<<add ("<lastBuildDate>" + date.netstandardstring (clock.now ()) + "</lastBuildDate>")
	add ("<docs>http://backend.userland.com/rss</docs>");
	add ("<generator>" + frontier.getProgramName () + "</generator>");
	bundle { //add the items for the indicated month
		local (i, adrpost, day, postmonth, postyear, hour, minute, second);
		for i = sizeof (adrblog^.posts) downto 1 {
			adrpost = @adrblog^.posts [i];
			date.get (adrpost^.when, @day, @postmonth, @postyear, @hour, @minute, @second);
			if (postmonth == month) and (postyear == year) {
				add ("<item>"); indentlevel++;
				if defined (adrpost^.title) {
					if sizeOf (adrpost^.title) > 0 {
						add ("<title>" + encode (adrpost^.title) + "</title>")}};
				if defined (adrpost^.link) {
					add ("<link>" + encode (adrpost^.link) + "</link>")};
				add ("<description>" + encode (string (adrpost^.text)) + "</description>");
				add ("<pubDate>" + date.netStandardString (adrpost^.when) + "</pubDate>");
				if defined (adrpost^.sourceName) and defined (adrpost^.sourceUrl) {
					add ("<source url=\"" + encode (adrpost^.sourceUrl) + "\">" + encode (adrpost^.sourceName) + "</source>")};
				if defined (adrpost^.sourceTime) {
					try {add ("<radioWeblogPost:sourceTime>" + date.netstandardstring (adrpost^.sourceTime) + "</radioWeblogPost:sourceTime>") }};
				if defined (adrpost^.enclosure) {
					with adrpost^.enclosure {
						if defined (error) {
							add ("<radioWeblogPost:enclosureError url=\"" + encode (url) + "\" error=\"" + encode (error) + "\"/>")}
						else {
							add ("<enclosure url=\"" + encode (url) + "\" length=\"" + length + "\" type=\"" + type + "\"/>")}}};
				if defined (adrpost^.categories) {
					local (adr);
					for adr in @adrpost^.categories {
						add ("<category>" + encode (nameof (adr^)) + "</category>")}};
				if defined (adrpost^.flNotOnHomePage) { //11/14/02 by DW
					if adrpost^.flNotOnHomePage {
						add ("<radioWeblogPost:flNotOnHomePage/>")}};
				add ("<radioWeblogPost:id>" + number (nameof (adrpost^)) + "</radioWeblogPost:id>");
				add ("</item>"); indentlevel--}}};
	add ("</channel>"); indentlevel--;
	add ("</rss>"); indentlevel--;
	bundle { //write the file but only if it changed
		local (flwrite = true);
		file.surefilepath (f);
		if file.exists (f) {
			if string (file.readwholefile (f)) == xmltext {
				flwrite = false}};
		if flwrite {
			file.writewholefile (f, xmltext)}}}
<<bundle //test code
	<<backupOneMonth (2001, 6)



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.