Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: REBOL Script to convert REBOL format to RSS XML

From: greggirwin:mindspring at: 30-Dec-2004 17:12

Hi Premshree, PP> Anyway, I wrote a small script that generates valid RSS 2.0 feeds from PP> the REBOL data for Carl's blog. The code is available here: PP> http://premshree.seacrow.com/code/rebol/carl-rss.r/download Very cool! PP> If there are improvements possible, please point so/do so. :) I did a quick re-hack of things, just to show you some different approaches. Others may chime in with more thoughts as well. Some of the things I thought about when evaluating your code: * Use path notation instead of SELECT * Don't use temporary vars if you don't need to * Tags are a valid datatype, you don't need to make them strings * JOIN (and REJOIN) build new strings, meaning lots of allocation and work for the GC. INSERT, APPEND, and their ilk just add on to an existing series; also saves reassigning the value. * See what refinements date! values offer to see if you need to convert them to strings to do what you want. * REPEAT is faster than FOR if you're going from 1 and incrementing by 1. FOREACH makes things even easier most times. I did a couple more advanced things in there (note the tick on the MAKE-ENTRY 'key parameter) and did some others to give you some things to take apart and think about. Holler away if you have questions. BTW, this was a very quick hack, so I don't know if, for example, TO-IDATE gives a valid format as far as RSS is concerned. -- Gregg REBOL [ Title: "RSS Generator for Carl's Blog" Date: 31-Dec-2004 File: %carl-rss.r Home: http://www.livejournal.com/~premshree Author: ["Premshree Pillai" "Gregg Irwin"] Version: 0.0.2 Purpose: { Generates valid RSS 2.0 feeds for Carl's blogs } Comment: { Massive code changes for instructional purposes. --Gregg } ] ;; channel data channel: [ title "Carl's REBOL Blog - Vive la REBOLution" link http://www.rebol.net/ description "describes this blog channel" language "en" ;"English" copyright "2005 Carl Sassenrath" generator "REBOL Messaging Language" ] ;; blog items go here items: [ [ title "Blog item title...." link http://www.rebol.net/cgi-bin/blog.r?view=0080 author "Carl Sassenrath" pubdate 30-Dec-2004/0:0:0 content {the blog goes here} ] [ title "Blog item title 2...." link http://www.rebol.net/cgi-bin/blog.r?view=0081 author "Carl Sassenrath" pubdate 31-Dec-2004/0:0:0 content {the blog 2 goes here} ] ] ;-- No Changes needed below this point ------------------------- make-entry: func [series 'key] [ rejoin [tab to tag! :key series/:key to tag! join #"/" :key] ] channel-entry: func ['key] [make-entry channel :key] channel-entries: func [keys [block!] /local result] [ result: copy "" foreach key keys [append result join channel-entry :key newline] result ] output: copy "" repend output [ <?xml version='1.0' encoding='utf-8' ?> <rss version='2.0'> newline <channel> newline channel-entries [title link description language copyright generator] ] foreach item items [ repend output [ tab <item> newline tab tab <guid isPermaLink='true'> item/link </guid> newline tab tab <pubDate> to-idate item/pubdate </pubDate> newline tab tab <title> item/title </title> newline tab tab <link> item/link </link> newline tab tab <description> item/content </description> newline tab </item> newline ] ] repend output [</channel> newline </rss>] ;print output ;halt write %carl-rss2.xml output