[REBOL] parse Slashdot news headers
From: al::bri::xtra::co::nz at: 7-Jul-2002 12:16
Joanna wrote:
> Has anyone made REBOL script that could parse Slashdot news headers and
view them on small window? All info (including links to files) are on
> http://slashdot.org/code.shtml
> There is no example on REBOL. IMHO it woud make an nice example how
REBOL/VIEW can be used. I looked those header files and they surely look
quite easy to parse, it would make nice and short view demo.
This just does the parsing into a block of objects from a local copy of the
file:
Rebol [
Name: 'Slashdot
Title: "Slashdot"
File: %Slashdot.r
Author: "Andrew Martin"
eMail: [Al--Bri--xtra--co--nz]
Web: http://valley.150m.com
Date: 7/July/2002
Version: 1.0.0
Purpose: {Parse Slashdot news headers into a Rebol format.}
Category: [util 1]
]
Slashdot: read %slashdot.xml
Text: string!
Content: [
copy Text to #"<"
]
WS: charset reduce [SP HT newline CR LF]
Story_Block: [
Title: string!
URL: url!
Time: date!
Author: string!
Department: string!
Topic: integer!
Comments: integer!
Section: string!
image: file!
]
Stories: make block! 20
probe parse/all Slashdot [
any WS
{<?xml version="1.0"?>} any WS
{<backslash} any WS
{xmlns:backslash="http://slashdot.org/backslash.dtd">} any WS
any [
"<story>" (
Story: make object! Story_Block
)
any WS
any [
[
"<title>" Content "</title>" (
Story/Title: Text
)
]
| [
"<url>" Content "</url>" (
Story/URL: load Text
)
]
| [
"<time>" Content "</time>" (
use [Date_Time] [
Date_Time: load Text
Story/Time: first Date_Time
Story/Time/time: last Date_Time
]
)
]
| [
"<author>" Content "</author>" (
Story/Author: Text
)
]
| [
"<department>" Content "</department>" (
Story/Department: Text
)
]
| [
"<topic>" Content "</topic>" (
Story/Topic: load Text
)
]
| [
"<comments>" Content "</comments>" (
Story/Comments: load Text
)
]
| [
"<section>" Content "</section>" (
Story/Section: Text
)
]
| [
"<image>" Content "</image>" (
Story/Image: to-file Text
)
]
| WS
]
"</story>" (
append Stories Story
)
any WS
]
"</backslash>" any WS
end
]
probe Stories
halt
It produces objects like:
make object! [
Title: "Am I Hot or Not"
URL: http://slashdot.org/article.pl?sid=02/07/06/1621206
Time: 6-Jul-2002/19:43:50
Author: "krow"
Department: "electric-dreams"
Topic: 164
Comments: 47
Section: "developers"
image: %topicupgrades.gif
]
That should provide a starting point for one's own work in writing View
code.
I hope that helps!
Andrew Martin
Bored Rebolutionary...
ICQ: 26227169 http://valley.150m.com/