Skip to content

Instantly share code, notes, and snippets.

@delbonis
Created November 15, 2019 19:14
Show Gist options
  • Save delbonis/e4b7c3aa451aae3af16c0b5305a1f2b8 to your computer and use it in GitHub Desktop.
Save delbonis/e4b7c3aa451aae3af16c0b5305a1f2b8 to your computer and use it in GitHub Desktop.
(use list :all)
(define (internal-add-feed id url interval)
(do
(println id)
(println url)
(println interval)))
(define (internal-add-rule id url optmap)
(do
(println id)
(println url)
(println (format "~z" optmap))))
(define (keywords-to-kvs li)
(cond
((>= (len li) 2)
(let ((name (first li))
(vals (take-while
(lambda (v)
(not (is 'keyword v)))
(slice li 1 (len li)))))
(apply append '()
(list name vals)
(keywords-to-kvs
(slice li
(+ 1 (len vals))
(len li))))))
((= (len li) 1) (list (first li)))
(else '())))
(macro (deffeed id url :rest opts)
`(internal-add-feed
,(string id)
,url
,(if (= (len opts) 0)
"default"
(first opts))))
(macro (defrule id regex :rest opts)
`(internal-add-rule
,(string id)
,regex
(keywords-to-kvs
,(concat (list 'list)
(map (lambda (v)
(if (is 'name v)
(string v)
v))
opts)))))
(deffeed foo "https://foo.com/")
(deffeed bar "https://bar.com/" "5m")
(defrule foobarrule "[0-9]+"
:title "Foo Bar"
:output somewhere
:onmatch (lambda (v)
(println v)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment