practical schemeの更新状況を取得する変換フィルタ
(use htmlprag)
(use pretty-print)
(use web-helper)
(use komono)
(use srfi-1) ;list
(use srfi-13) ;string
(use sxml.sxpath)
(use sxml.serializer)
(use sxml.tools)
;(use gauche.charconv)
(use gauche.generator)
(use text.tree)
(define news-title "Gauche - A Scheme Implementation")
(define news-uri "http://practical-scheme.net/gauche/index-j.html")
; htmlpragは閉じタグの省略に対応できていない模様。
; <dd>の閉じタグ省略に対応できていない。
(define (kugiri-pred e)
;#?=e
(and (pair? e)
(or
(case (sxml:name e)
( 'dt #t )
( 'h2 #t )
( 'dl ((if-sxpath "/dt") e) ) ; htmlpragの不具合のため、dlが認識できていない
( 'p
(and-let* [[patext ((if-car-sxpath "/a/text()") e)]]
(string=? patext "古いニュース")) )
(else #f) ) ) ) )
(define parse
($ (^s
;#?=s
(receive (spl brk) (list-split s kugiri-pred)
`( (header . ,(car spl))
(items .
,(zip (map ($ string-trim-both $ sxml->string $) brk) (cdr spl)) ) ) ) )
$ (sxpath "//div[@class='content']/*")
;$ tee pretty-print
$) )
(define (generate-rss d)
;#?=(assoc-ref d 'header)
($ srl:sxml->xml
`(rdf
(channel
(title ,news-title )
(link ,news-uri )
(description ,($ string-concatenate $ map srl:sxml->html $ assoc-ref d 'header) )
)
,@(map
(^x
;#?=x
`(item
(title ,(car x))
(description ,($ string-concatenate $ map srl:sxml->html $ cdr x ) )) )
(assoc-ref d 'items) ) ))
)
(define (main args)
($ print
$ generate-rss
$ parse
$ port->sxml html->sxml (standard-input-port)
) 0 )
; $ sxml-get-http-uri news-uri