Created
February 20, 2013 19:18
-
-
Save xsyn/4998355 to your computer and use it in GitHub Desktop.
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
(ns sumphonos.import | |
(:use [compojure.core] | |
[ring.middleware.params] | |
[ring.middleware.multipart-params] | |
[ring.adapter.jetty] | |
[clojure.java.io :only [reader copy]] | |
[hiccup.page :only [include-js]]) | |
(:require [clojure-csv.core :as csv] | |
[sumphonos.database :as mg] | |
[sumphonos.views.layout :as layout]) | |
(:import [java.io File])) | |
(defn parse-row [row] | |
(let [v (first (csv/parse-csv row :delimiter \;))] | |
(zipmap [:email :name] v))) | |
(defn parse-file [filename] | |
(with-open [file (reader filename)] | |
(doseq [line (line-seq file)] | |
(let [record (parse-row line)] record)))) | |
(defn upload-file [file] | |
(let [file-name (file :filename) | |
size (file :size) | |
actual-file (file :tempfile)] | |
(do | |
{:status 200 | |
:headers {"Content-Type" "text/html"} | |
:body (layout/loading | |
[:h1 "Uploading file: " file-name " please be patient."] | |
;[:h1 size] | |
)}) | |
(copy actual-file (File. (format "/tmp/%s" file-name))) | |
{:status 200 | |
:headers {"Content-Type" "text/html"} | |
:body (layout/loading | |
[:h1 "Importing users, please be patient."] | |
[:h1 size] | |
[:h1 (parse-file actual-file)])} | |
;; Add another step to redirect here | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment