Last active
April 22, 2024 19:29
-
-
Save wjlafrance/e3e4ccca252c559d752902dfba36f1b6 to your computer and use it in GitHub Desktop.
Prepare to copy and zip JPG's and DNG's for upload to NAS fileshare
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
#!/usr/bin/env bb | |
(use '[clojure.string :as str]) | |
(def sh-newline-indent " \\\n ") | |
(defn mk-file-list | |
[files] | |
(->> files | |
(partition 4 4 []) ; providing even an empty padding collection makes partition return non-full slices | |
(map #(str/join " " %)) | |
(str/join " \\\n "))) | |
(let [directory "/Users/lafrance/Desktop/Scanned Documents" | |
files (->> directory | |
clojure.java.io/file | |
file-seq | |
(map #(.getName %)) | |
(filter #(re-matches #"^\d{4}\-\d{2}\-\d{2}\-.+\.(dng|jpg)$" %)) | |
sort) | |
pick-date (->> files | |
(map #(subs % 0 10)) | |
set | |
sort | |
last) | |
pick-files (filter #(str/starts-with? % pick-date) files) | |
jpgs (filter #(str/ends-with? % ".jpg") pick-files) | |
dngs (filter #(str/ends-with? % ".dng") pick-files) | |
_ (println "Name of user: ") | |
username (read-line) | |
_ (println "Name of project: ") | |
project (read-line) | |
jpgs-zipfile (str pick-date "-" username "-" project "-jpgs.zip") | |
dngs-zipfile (str pick-date "-" username "-" project "-dngs.zip")] | |
(spit "import-and-upload.sh" | |
(str "DIR=\"" directory "\"" | |
"\n" | |
"mv" sh-newline-indent | |
(->> pick-files | |
(map #(str "\"$DIR/" % "\"")) | |
mk-file-list) | |
sh-newline-indent | |
"." | |
"\n" | |
"zip " jpgs-zipfile sh-newline-indent | |
(mk-file-list jpgs) | |
"\n" | |
"zip " dngs-zipfile sh-newline-indent | |
(mk-file-list dngs) | |
"\n" | |
"scp" sh-newline-indent | |
jpgs-zipfile sh-newline-indent | |
dngs-zipfile sh-newline-indent | |
"columbia:/tank/fileshare/" username | |
"\n")) | |
(println "Emitted script. Please inspect before running:\n" | |
" less ./import-and-upload.sh\n" | |
" chmod +x ./import-and-upload.sh\n" | |
" ./import-and-upload.sh\n" | |
" rm *.jpg *.dng")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment