poolboi now generates a full rss log instead of overwriting it each time

main
m455 2 years ago committed by Jesse Laprade
parent 5a0a79fe0b
commit f6e8878d9c
  1. 8
      README.md
  2. 37
      poolboi.rkt

@ -1,8 +1,8 @@
# poolboi
an irc bot that keeps a log of topics from [tilde.town](http://tilde.town)'s #javapool irc channel
an irc bot that keeps a log of topics from [tilde.town](https://tilde.town)'s `#javapool` irc channel.
currently, the following logs exist:
currently, the following logs have been generated:
* [plaintext log](http://tilde.town/~m455/javapool.txt)
* [rss feed](http://tilde.town/~m455/javapool.rss)
- [plaintext log](http://tilde.town/~m455/javapool.txt)
- [rss feed](http://tilde.town/~m455/javapool.rss)

@ -27,6 +27,8 @@
(define rss-output-file (string-append "/home/m455/public_html/" rss-file))
(define rss-file-url (string-append rss-url-base "/" rss-file))
(define banned-shit "]]>")
(define rss-header
(format
#<<string-block
@ -77,21 +79,34 @@ string-block
(define (get-date)
(shell-command "date +'%Y-%m-%d'"))
(define (get-date-rss)
(shell-command (format "date -Rd'~a'" (get-date))))
(define (date->rss-date date)
(shell-command (format "date -Rd'~a'" date)))
;; ------------------------------------------------------------------------
;; Commands
;; ------------------------------------------------------------------------
(define (update-logs topic)
(let* ([plain-text-log (string-append (get-date) "\t" topic "\n")]
[item (format rss-item topic rss-file-url topic (get-date-rss))]
[rss-log (format "~a~a~a" rss-header item rss-footer)])
;; write to javapool.txt
(display-to-file plain-text-log output-file #:exists 'append)
;; write to javapool.rss
(display-to-file rss-log rss-output-file #:exists 'truncate)))
(define (file->dates-and-topics file)
(map (lambda (x) (string-split x "\t"))
(file->lines file)))
(define (update-logs channel-topic)
(let ([topic (string-replace channel-topic banned-shit "")])
;; append to javapool.txt
(display-to-file (string-append (get-date) "\t" topic "\n")
output-file
#:exists
'append)
;; create javapool.rss
;; header
(display-to-file rss-header rss-output-file #:exists 'truncate)
;; items
(for ([pair (file->dates-and-topics output-file)])
(let* ([date (date->rss-date (car pair))]
[topic-rss (cadr pair)]
[item (format rss-item topic-rss rss-file-url topic-rss date)])
(display-to-file item rss-output-file #:exists 'append)))
;; footer
(display-to-file rss-footer rss-output-file #:exists 'append)))
;; ------------------------------------------------------------------------
;; IRC builders

Loading…
Cancel
Save