Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahTheDuke authored and Noah Bogart committed Sep 26, 2018
1 parent 377e15d commit d489579
Show file tree
Hide file tree
Showing 19 changed files with 3,690 additions and 4,323 deletions.
8 changes: 6 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
[crypto-password "0.2.0"]
[binaryage/devtools "0.9.7"]
[digest "1.4.6"]
[http-kit "2.2.0"]
[http-kit "2.3.0"]
[org.slf4j/slf4j-nop "1.7.12"]
[jwarwick/trello "0.3.3"]
[clj-time "0.14.2"]
[com.draines/postal "2.0.2"]
[throttler "1.0.0"]
[clj-http "3.7.0"]
[reagent "0.8.1"]
[eftest "0.1.4"]
[cljsjs/react "16.4.1-0"]
[cljsjs/react-dom "16.4.1-0"]
[org.clojars.frozenlock/reagent-modals "0.2.8"]
Expand All @@ -40,6 +41,7 @@
[lein-figwheel "0.5.16"]
[com.gfredericks/lein-sha-version "0.1.1-p1"]
[lein-ring "0.9.7"]
[lein-eftest "0.5.2"]
[lein-exec "0.3.7"]]

:profiles {:dev {:dependencies [[figwheel-sidecar "0.5.16"]
Expand All @@ -49,6 +51,7 @@
:source-paths ["src/clj" "src/cljs" "src/dev" "src/cljc"]}}

:aliases {"fetch" ["run" "-m" "tasks.fetch/fetch"]
"dumbrepl" ["trampoline" "run" "-m" "clojure.main/main"]
"add-art" ["run" "-m" "tasks.altart/add-art"]
"delete-duplicate-users" ["run" "-m" "tasks.db/delete-duplicate-users"]
"card-coverage" ["run" "-m" "tasks.cards/test-coverage"]}
Expand All @@ -67,6 +70,7 @@

;; Misc
:test-paths ["test/clj"]
:eftest {:report eftest.report.pretty/report}

:ring {:handler web.api/app}

Expand Down Expand Up @@ -103,6 +107,6 @@
:css-dirs ["resources/public/css"]}

;; Set timeout to 2 min to allow for full compilation after a clean.
:repl-options {:timeout 120000
:repl-options {:timeout 180000
:init-ns web.core
:init (do (use 'web.lobby) (-main "dev"))})
39 changes: 20 additions & 19 deletions src/clj/tasks/nrdb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
[clojure.data :as data]
[clojure.java.io :as io]
[clojure.pprint :refer [pprint] :as pprint]
[cheshire.core :as json]))
[cheshire.core :as json]
[tasks.utils :refer [slugify]]))

(declare faction-map)

Expand Down Expand Up @@ -171,13 +172,6 @@
:cycle_position (:position c)
:cycle (:name c))))

(defn deaccent
"Remove diacritical marks from a string, from http://www.matt-reid.co.uk/blog_post.php?id=69"
[s]
(if (nil? s) ""
(let [normalized (java.text.Normalizer/normalize s java.text.Normalizer$Form/NFD)]
(string/replace normalized #"\p{InCombiningDiacriticalMarks}+" ""))))

(defn- prune-null-fields
"Remove specified fields if the value is nil"
[c fields]
Expand Down Expand Up @@ -211,7 +205,7 @@
:cycle_code (:cycle_code s)
:rotated (:rotated s)
:image_url (get-uri c s)
:normalizedtitle (string/lower-case (deaccent (:title c)))))))
:normalizedtitle (slugify (:title c))))))

(defn fetch-data
"Read NRDB json data. Modify function is mapped to all elements in the data collection."
Expand Down Expand Up @@ -266,7 +260,7 @@
; wait for all the GETs to complete
(:status @resp)))
(println "Finished downloading card art")))))

(defn fetch-cards
"Find the NRDB card json files and import them."
[download-fn {:keys [collection path] :as card-table} sets download-images]
Expand All @@ -275,15 +269,22 @@
(partial add-card-fields sets)
(fn [c d] true))
cards-replaced (->> cards
vals
(group-by :title)
(filter (fn [[k v]] (>= (count v) 2)))
vals
(map (fn [[c1 c2]] [(:title c1)
(if (:rotated c1) (:code c1) (:code c2))
(if (:rotated c1) (:code c2) (:code c1))]))
(reduce rotate-cards cards))]
(spit "data/cards.json" (str cards))
vals
(group-by :title)
(filter (fn [[k v]] (>= (count v) 2)))
vals
(map (fn [[c1 c2]] [(:title c1)
(if (:rotated c1) (:code c1) (:code c2))
(if (:rotated c1) (:code c2) (:code c1))]))
(reduce rotate-cards cards))]
(doseq [card (vals cards-replaced)]
(let [file-name (str "data/cards/" (:normalizedtitle card) ".edn")]
(io/make-parents file-name)
;; Below taken from https://coderwall.com/p/mxbxdq/clojure-fast-pretty-print-writes-to-file
(with-open [w (clojure.java.io/writer file-name)]
(binding [*out* w
clojure.pprint/*print-right-margin* 350]
(clojure.pprint/write (into (sorted-map) card))))))
(mc/remove db collection)
(mc/insert-batch db collection (vals cards-replaced))
(when download-images
Expand Down
45 changes: 45 additions & 0 deletions src/clj/tasks/utils.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
(ns tasks.utils
"utilities for the tasks"
(:require [clojure.string :as string]))

(defn type->dir
[card]
(case (:type card)
"Agenda" "agendas"
"Asset" "assets"
"Event" "events"
"Fake-Identity" "identities"
"Hardware" "hardware"
"ICE" "ice"
"Identity" "identities"
"Operation" "operations"
"Program" (if (and (:subtype card)
(> (.indexOf (:subtype card) "Icebreaker") -1))
"icebreakers"
"programs")
"Resource" "resources"
"Upgrade" "upgrades"))

(defn deep-merge [v & vs]
;; Pulled from https://gist.github.com/danielpcox/c70a8aa2c36766200a95#gistcomment-2313926
(letfn [(rec-merge [v1 v2]
(if (and (map? v1) (map? v2))
(merge-with deep-merge v1 v2)
v2))]
(if (some identity vs)
(reduce #(rec-merge %1 %2) v vs)
v)))

(defn slugify
"As defined here: https://you.tools/slugify/"
([s] (slugify s "-"))
([s sep]
(if (nil? s) ""
(as-> s s
(java.text.Normalizer/normalize s java.text.Normalizer$Form/NFD)
(string/replace s #"[\P{ASCII}]+" "")
(string/lower-case s)
(string/trim s)
(string/split s #"[\p{Space}\p{Punct}]+")
(filter seq s)
(string/join sep s)))))
Loading

0 comments on commit d489579

Please sign in to comment.