Update RSS library

db4
Slava Pestov 2008-04-17 04:15:37 -05:00
parent a37c490f3e
commit 1803301800
1 changed files with 9 additions and 8 deletions

View File

@ -4,7 +4,8 @@ IN: rss
USING: xml.utilities kernel assocs xml.generator USING: xml.utilities kernel assocs xml.generator
strings sequences xml.data xml.writer strings sequences xml.data xml.writer
io.streams.string combinators xml xml.entities io.files io io.streams.string combinators xml xml.entities io.files io
http.client namespaces xml.generator hashtables ; http.client namespaces xml.generator hashtables
calendar.format accessors continuations ;
: ?children>string ( tag/f -- string/f ) : ?children>string ( tag/f -- string/f )
[ children>string ] [ f ] if* ; [ children>string ] [ f ] if* ;
@ -25,7 +26,7 @@ C: <entry> entry
[ "link" tag-named children>string ] keep [ "link" tag-named children>string ] keep
[ "description" tag-named children>string ] keep [ "description" tag-named children>string ] keep
f "date" "http://purl.org/dc/elements/1.1/" <name> f "date" "http://purl.org/dc/elements/1.1/" <name>
tag-named ?children>string tag-named ?children>string rfc3339>timestamp
<entry> ; <entry> ;
: rss1.0 ( xml -- feed ) : rss1.0 ( xml -- feed )
@ -41,7 +42,7 @@ C: <entry> entry
[ "link" tag-named ] keep [ "link" tag-named ] keep
[ "guid" tag-named dupd ? children>string ] keep [ "guid" tag-named dupd ? children>string ] keep
[ "description" tag-named children>string ] keep [ "description" tag-named children>string ] keep
"pubDate" tag-named children>string <entry> ; "pubDate" tag-named children>string rfc3339>timestamp <entry> ;
: rss2.0 ( xml -- feed ) : rss2.0 ( xml -- feed )
"channel" tag-named "channel" tag-named
@ -59,7 +60,7 @@ C: <entry> entry
[ children>string ] if [ children>string ] if
] keep ] keep
{ "published" "updated" "issued" "modified" } any-tag-named { "published" "updated" "issued" "modified" } any-tag-named
children>string <entry> ; children>string rfc3339>timestamp <entry> ;
: atom1.0 ( xml -- feed ) : atom1.0 ( xml -- feed )
[ "title" tag-named children>string ] keep [ "title" tag-named children>string ] keep
@ -78,10 +79,10 @@ C: <entry> entry
: download-feed ( url -- feed ) : download-feed ( url -- feed )
#! Retrieve an news syndication file, return as a feed tuple. #! Retrieve an news syndication file, return as a feed tuple.
http-get-stream rot success? [ http-get-stream swap code>> success? [
nip read-feed read-feed
] [ ] [
2drop "Error retrieving newsfeed file" throw dispose "Error retrieving newsfeed file" throw
] if ; ] if ;
! Atom generation ! Atom generation
@ -95,7 +96,7 @@ C: <entry> entry
"entry" [ "entry" [
dup entry-title "title" { { "type" "html" } } simple-tag*, dup entry-title "title" { { "type" "html" } } simple-tag*,
"link" over entry-link "href" associate contained*, "link" over entry-link "href" associate contained*,
dup entry-pub-date "published" simple-tag, dup entry-pub-date timestamp>rfc3339 "published" simple-tag,
entry-description [ "content" { { "type" "html" } } simple-tag*, ] when* entry-description [ "content" { { "type" "html" } } simple-tag*, ] when*
] tag, ; ] tag, ;