-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhn.clj
28 lines (24 loc) · 857 Bytes
/
hn.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
; scrape top new articles from hn
(defn fetch-article [id]
(php/json_decode
(php/file_get_contents
(str "https://hacker-news.firebaseio.com/v0/item/" id ".json"))))
(defn fetch-top-articles []
(let [ids (php/json_decode
(php/file_get_contents
"https://hacker-news.firebaseio.com/v0/topstories.json"))
ids (php/array_slice ids 0 10)]
(php/array_map
(fn [id] (fetch-article id))
ids)))
(defn main []
(php/header "Content-type: text/plain")
(let [articles (fetch-top-articles)
articles (php/array_map
(fn [article]
(let [article (php->clj article)]
(str (get article "title") "\n"
(get article "url") "\n")))
articles)]
(print (php/join "\n" articles))))
(main)