RSS cleanups
parent
4369dc61c2
commit
0fb6ce87e2
|
@ -1,5 +1,9 @@
|
||||||
USING: rss io.files tools.test ;
|
USING: rss io kernel io.files tools.test ;
|
||||||
IN: temporary
|
|
||||||
|
: load-news-file ( filename -- feed )
|
||||||
|
#! Load an news syndication file and process it, returning
|
||||||
|
#! it as an feed tuple.
|
||||||
|
<file-reader> read-feed ;
|
||||||
|
|
||||||
[ T{
|
[ T{
|
||||||
feed
|
feed
|
||||||
|
@ -34,4 +38,3 @@ IN: temporary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} ] [ "extra/rss/atom.xml" resource-path load-news-file ] unit-test
|
} ] [ "extra/rss/atom.xml" resource-path load-news-file ] unit-test
|
||||||
[ " & & hi" ] [ " & & hi" &>& ] unit-test
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2006 Chris Double, Daniel Ehrenberg.
|
! Copyright (C) 2006 Chris Double, Daniel Ehrenberg.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
IN: rss
|
IN: rss
|
||||||
USING: xml.utilities kernel promises parser-combinators assocs
|
USING: xml.utilities kernel assocs
|
||||||
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 ;
|
||||||
|
@ -62,23 +62,17 @@ C: <entry> entry
|
||||||
children>string <entry>
|
children>string <entry>
|
||||||
] map <feed> ;
|
] map <feed> ;
|
||||||
|
|
||||||
: feed ( xml -- feed )
|
: xml>feed ( xml -- feed )
|
||||||
dup name-tag {
|
dup name-tag {
|
||||||
{ "RDF" [ rss1.0 ] }
|
{ "RDF" [ rss1.0 ] }
|
||||||
{ "rss" [ rss2.0 ] }
|
{ "rss" [ rss2.0 ] }
|
||||||
{ "feed" [ atom1.0 ] }
|
{ "feed" [ atom1.0 ] }
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
: read-feed ( string -- feed )
|
: read-feed ( stream -- feed )
|
||||||
! &>& ! this will be uncommented when parser-combinators are fixed
|
[ read-xml ] with-html-entities xml>feed ;
|
||||||
[ string>xml ] with-html-entities feed ;
|
|
||||||
|
|
||||||
: load-news-file ( filename -- feed )
|
: download-feed ( url -- feed )
|
||||||
#! Load an news syndication file and process it, returning
|
|
||||||
#! it as an feed tuple.
|
|
||||||
<file-reader> [ contents read-feed ] keep stream-close ;
|
|
||||||
|
|
||||||
: news-get ( url -- feed )
|
|
||||||
#! Retrieve an news syndication file, return as a feed tuple.
|
#! Retrieve an news syndication file, return as a feed tuple.
|
||||||
http-get rot 200 = [
|
http-get rot 200 = [
|
||||||
nip read-feed
|
nip read-feed
|
||||||
|
@ -90,7 +84,7 @@ C: <entry> entry
|
||||||
: simple-tag, ( content name -- )
|
: simple-tag, ( content name -- )
|
||||||
[ , ] tag, ;
|
[ , ] tag, ;
|
||||||
|
|
||||||
: (generate-atom) ( entry -- )
|
: entry, ( entry -- )
|
||||||
"entry" [
|
"entry" [
|
||||||
dup entry-title "title" simple-tag,
|
dup entry-title "title" simple-tag,
|
||||||
"link" over entry-link "href" associate contained*,
|
"link" over entry-link "href" associate contained*,
|
||||||
|
@ -98,9 +92,12 @@ C: <entry> entry
|
||||||
entry-description "content" simple-tag,
|
entry-description "content" simple-tag,
|
||||||
] tag, ;
|
] tag, ;
|
||||||
|
|
||||||
: generate-atom ( feed -- xml )
|
: feed>xml ( feed -- xml )
|
||||||
"feed" [
|
"feed" { { "xmlns" "http://www.w3.org/2005/Atom" } } [
|
||||||
dup feed-title "title" simple-tag,
|
dup feed-title "title" simple-tag,
|
||||||
"link" over feed-link "href" associate contained*,
|
"link" over feed-link "href" associate contained*,
|
||||||
feed-entries [ (generate-atom) ] each
|
feed-entries [ entry, ] each
|
||||||
] make-xml ;
|
] make-xml* ;
|
||||||
|
|
||||||
|
: write-feed ( feed -- xml )
|
||||||
|
feed>xml write-xml ;
|
||||||
|
|
Loading…
Reference in New Issue