Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ITSecMedia/472e7629ca2536340941a9ba2da45555 to your computer and use it in GitHub Desktop.
Save ITSecMedia/472e7629ca2536340941a9ba2da45555 to your computer and use it in GitHub Desktop.
;;
;; Take a textfile which contains a copy of the raw html of a humblebundle user account download
;; select the download page html table with the mouse copy+paste in a textfile
;; Use this file to create a list of folders based on the download names.
;;
;; === TEXT FILE CONTENT EXAMPLE ===
;; Book of Making – Volume 1
;; Raspberry Pi Press
;; PDF
;; 49 MB md5
;;
;; Book of Making – Volume 2
;; Raspberry Pi Press
;; PDF
;; 51.6 MB md5
;;
;; The Official Raspberry Pi Projects Book – Volume 5
;; Raspberry Pi Press
;; PDF
;; 57.9 MB md5
;;
(ns console.humblebundle
(:require [clojure.java.io :as io]
[clojure.string :as str]))
;; read the file content
(def file-content (slurp "humblebundle.txt"))
;; split the text in blocks by empty newline
;; split the resulting text-blocks in a list of lists
;; filter valid lists -> forget the invalids
;; extract the book titles -> first item in a book-list
(def humblebundle-book-titles (->> (str/split file-content #"(\r\n)")
(partition-by #(= % ""))
(filter #(> (count %) 1))
(map #(first %))))
(defn sanitize-name
"Sanitize relative efficiently a given [name:string]
by replacing forbidden chars with a given [char-alt:char]"
[name char-alt]
(let [illegal-fs-chars #{\\ \/ \: \* \? \" \< \> \|}]
(apply str (doall
(map
#(if (contains? illegal-fs-chars %)
char-alt
%)
(seq name))))))
(defn create-directory
"Create a folder based on a given name"
[name]
(if
(.mkdir (java.io.File. (str "data/" (sanitize-name name \_))))
(str "OK =>" name)
(str "PROBLEM =>" name)))
;; realize task -> apply create-folder function on the list of book-titles
(doall (map create-directory humblebundle-book-titles))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment