Skip to content

Instantly share code, notes, and snippets.

@ToxicFrog
Created October 6, 2013 00:27
Show Gist options
  • Save ToxicFrog/864980d0ffc5ca7614cb to your computer and use it in GitHub Desktop.
Save ToxicFrog/864980d0ffc5ca7614cb to your computer and use it in GitHub Desktop.
(ns runewords.core
(:gen-class)
(:require [crouton.html :as html])
(:require [clojure.set :as set]))
(defn- tag-seq [tag body]
(filter #(= tag (:tag %)) (xml-seq body)))
(defn- content-row? [row]
(or
(#{"#101010" "#202020"}
(some->> row :content (some :attrs) :bgcolor))
(= "#908858"
(some->> row :content (some :content) (some :attrs) :color))))
(defn- tag-content [tag]
(if (string? tag) tag
(->> tag :content
(map tag-content)
(apply str))))
(defn- parse-word [runes]
(.split runes "[+ ]+"))
; cell ordering is name - valid items - rune word - effects
(defn runeword-from-tr [tr]
(let [[name item runes stats] (->> tr (tag-seq :td) (map tag-content))]
{:name name
:item item
:word (parse-word runes)
:stats stats}))
(defn- runewords-from-trs [tr-seq]
(->> tr-seq
(filter content-row?)
(map runeword-from-tr)))
(defn- load-runewords [file]
(->> file html/parse (tag-seq :tr) runewords-from-trs))
(defn- can-make-with [runes runeword]
(set/subset? (set (:word runeword)) runes))
(defn- pretty-print [runeword]
(printf "%s [%s]\n\t%s\n"
(:name runeword)
(->> (:word runeword) (interpose " ") (apply str))
(:item runeword)))
(defn -main [& args]
(->> (concat
(load-runewords "resources/runewords-original.shtml")
(load-runewords "resources/runewords-110.shtml")
(load-runewords "resources/runewords-111.shtml")
(load-runewords "resources/gemwords.html")
(load-runewords "resources/runewords.html"))
(filter #(can-make-with (set args) %))
(map pretty-print)
dorun))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment