;;;
;;; generate rss-1.0 from recent logs
;;;
;;; (c)2008 naoya_t
;;;
(require "./setting")
(require "./lib/rawlog")
(use srfi-19) ; date
(define today-jd (date->julian-day (current-date)))
(define (rss-1.0 links items)
(string-append
"
IRC " irc-channel " log
" logview-root-url "
" irc-channel " on " irc-server "
"
(string-join (map (cut format " \n" <>) links) "")
"
"
(string-join items "")
"
"))
(define (hh:mm:dd->sec hh:mm:dd)
(fold (lambda (x y) (+ x (* y 60))) 0 (map string->number (string-split hh:mm:dd ":"))))
(let loop ([ofs 1] [links '()] [items '()])
(let ([last_t 86399]
[sep #f])
(define (plain-filter timestamp user cmd room msg)
(let1 msg (regexp-replace #/ msg "<")
(case cmd
[(JOIN PART QUIT) #f]
[(PRIVMSG)
(let1 t (hh:mm:dd->sec timestamp)
(let1 s (format "~a~a <~a> ~a
\n"
(if (< (+ last_t 3600) t) "
\n" "") ; separator
timestamp user msg)
(set! last_t t)
s))]
[(NICK)
(format "~a <~a => ~a>
\n" timestamp user msg)]
[(TOPIC)
(format "~a <~a> TOPIC => ~a>
\n" timestamp user msg)]
[else #f])))
(let* ([d (julian-day->date (- today-jd ofs))]
[date-str (date->string d "~Y-~m-~d")] ;;(format "~4,'0d-~2,'0d-~2,'0d" (date-year d) (date-month d) (date-day d))]
[content (daily-log date-str plain-filter)])
(if (and (<= ofs 3) content)
(let* ([link (logview-url date-str)]
[description (string-append (substring content 0 (min (string-length content) 100)) " ...")]
[content-br (regexp-replace #/\n/ content "
\n")]
[title date-str]
[subject date-str]
[item (format
" -
~a
~a
~a
~a
~aT00:05:00+09:00
" link title link description subject date-str content-br)
])
(loop (+ ofs 1)
(cons link links)
(cons item items)))
(with-output-to-file (string-append rss-output-dir "/" rdf-name)
(lambda ()
(print (rss-1.0 (reverse! links) (reverse! items)))
))
))))