Skip to content

Instantly share code, notes, and snippets.

@tolitius
Last active January 1, 2016 23:59
Show Gist options
  • Save tolitius/8219862 to your computer and use it in GitHub Desktop.
Save tolitius/8219862 to your computer and use it in GitHub Desktop.
contacts extracted from a phone to wedding invitations
;; GIVEN (a text file):
;; John Smith & Jane Smirnoff,,2,2,"2800 West 21st Ave Apt 8C, Brooklyn, NY 11237",
;; Mr. & Mrs. Anatoly Clojurevich & Family,,4,2,"877 Greatview Road, Silicon Valley, PA 19006",
;; NEED (a text file):
;; John Smith & Jane Smirnoff
;; 2800 West 21st Ave Apt 8C
;; Brooklyn, NY 11237
;;
;; Mr. & Mrs. Anatoly Clojurevich & Family
;; 877 Greatview Road
;; Silicon Valley, PA 19006
(defn parse-address [line]
(when line
(let [[a-line _] (take-last 2 (split line #"\""))
[street city state] (if a-line
(split a-line #", ")
["none" "none" "none"])]
(str street "\n" city ", " state))))
(defn to-invitation [contact]
(let [[names a-line] (split contact #",,")
address (parse-address a-line)]
(str names "\n" address "\n\n")))
(map #(spit "resources/invitations.txt" (to-invitation %) :append true)
(split-lines (slurp "resources/wedding-list.txt")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment