Skip to content

Instantly share code, notes, and snippets.

@hashrocketeer
Created September 14, 2012 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hashrocketeer/3725358 to your computer and use it in GitHub Desktop.
Save hashrocketeer/3725358 to your computer and use it in GitHub Desktop.
(ns hackerfews.core
2 (:require [net.cgrand.enlive-html :as html]))
3
4 (def url (java.net.URI. "http://news.ycombinator.com/"))
5
6 (defn titles
7 [docx] (flatten (map :content (html/select docx [:td.title :a]))))
8
9 (defn numbers-in-nodes
10 [docx selector] (let [x (flatten (map :content (html/select docx selector)))]
11 (map #(Integer. (or (re-find #"\d+" %) "0")) x)))
12
13 (defn comment-counts
14 [docx]
15 (numbers-in-nodes docx [:td.subtext html/last-child]))
16
17 (defn points
18 [docx]
19 (numbers-in-nodes docx [:td.subtext html/first-child]))
20
21 (defn articles
22 [resource] (map (fn [t c p] { :title t :comments c :points p}) (titles resource) (comment-counts resource) (points resource)))
23
24 (defn get-url
25 [url] (articles (html/html-resource url)))
26
27 (defn -main []
28 (let [matching-articles (filter (fn [article] (< (:comments article) (:points article) )) (get-url url))]
29 (map :title matching-articles)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment