Created
November 12, 2017 20:29
-
-
Save alloy-d/35d53b974e5ce8e16fb009a8d394820a to your computer and use it in GitHub Desktop.
Silly script for reformatting the timestamps in log file names.
This file contains 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
#!/usr/bin/env boot | |
;; vim: ft=clojure | |
(set-env! :dependencies '[[clojure.java-time "0.3.0"] | |
[me.raynes/fs "1.4.6"]]) | |
(require '[clojure.string :as s] | |
'[me.raynes/fs :as fs] | |
'[java-time :as t]) | |
(defn- time-part [name] | |
(second (re-matches #"results-(.+)\.edn" name))) | |
(defn -main [& args] | |
(eval (get-actions))) | |
(defn get-actions [] | |
(into | |
[] | |
(comp | |
(map (fn [file] | |
{:file file | |
:base-name (fs/base-name file)})) | |
(map #(assoc % :results-time (time-part (:base-name %)))) | |
(filter :results-time) | |
(map #(assoc % :results-time | |
(s/replace (:results-time %) | |
#"(?<=[-+])(\d\d)(\d\d)$" | |
"$1:$2"))) | |
(map #(assoc % :parsed-time | |
(t/zoned-date-time (:results-time %)))) | |
(map (fn [thing] | |
(let [from-path (:base-name thing) | |
to-path (str "results-" | |
(t/format :iso-offset-date-time (:parsed-time thing)) | |
".edn")] | |
`(fs/rename | |
~from-path | |
~to-path))))) | |
(fs/list-dir fs/*cwd*))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment