Skip to content

Instantly share code, notes, and snippets.

@xsyn
Created February 20, 2013 19:18
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 xsyn/4998355 to your computer and use it in GitHub Desktop.
Save xsyn/4998355 to your computer and use it in GitHub Desktop.
(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