Created
August 21, 2015 02:57
-
-
Save calebsmith/4a00dad7b92d38299ac7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns xkcd-helper | |
(:require [clojure.string :as s] | |
[net.cgrand.enlive-html :as enl])) | |
(def base-url "https://xkcd.com/") | |
(def build-url #(str base-url % "/")) | |
(def fetch-url (comp enl/html-resource #(new java.net.URL %))) | |
(def fetch-url-on-num (comp fetch-url build-url)) | |
(defn get-transcript [cont] | |
(first (:content (first (enl/select cont [:#transcript]))))) | |
(defn get-comic [cont] | |
(:src (:attrs (second (:content (first (enl/select cont [:#comic]))))))) | |
(defn xkcd [comic-num] | |
(let [html (fetch-url-on-num comic-num)] | |
((juxt (comp #(str "https:" %) get-comic) (comp s/split-lines get-transcript)) html))) | |
(map xkcd [224 297]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment