[REBOL] Re: REBOL Script to convert REBOL format to RSS XML
From: premshree:pillai:gma:il at: 31-Dec-2004 14:24
Hi Gregg,
This looks nice. Thanks! :)
Some rework may be required for the pubDate, though. The to-idate
returns something like "Thu, 30 Dec 2004 0:00 +0000". For it to be
validated, it must be "Thu, 30 Dec 2004 00:00:00 +0000". The change is
required in the time, that is. It's a minor problem, though.
If anybody's interested in further hacking, these URLs could be useful:
* RSS 2.0 specification: http://blogs.law.harvard.edu/tech/rss
* Valid date types for RSS 2.0:
http://feedvalidator.org/docs/error/InvalidRFC2822Date.html
On Thu, 30 Dec 2004 17:12:12 -0700, Gregg Irwin
<[greggirwin--mindspring--com]> wrote:
> 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
>
> --
> To unsubscribe from the list, just send an email to rebol-request
> at rebol.com with unsubscribe as the subject.
>
--
Premshree Pillai
http://www.livejournal.com/~premshree