Skip to content

Instantly share code, notes, and snippets.

@nbessi
Last active December 11, 2015 12:49
Show Gist options
  • Save nbessi/4603621 to your computer and use it in GitHub Desktop.
Save nbessi/4603621 to your computer and use it in GitHub Desktop.
(ns repl.xml_to_csv
(:use [hiccup.core]
[clojure-csv.core :as csv]))
(defn csv-data [] (csv/parse-csv (slurp "/Users/nbessi/Downloads/doc/zip.csv")))
(defn render-line [line]
(html [:record {:id (line 0), :model "res.better.zip"}
[:field {:name "name"} (line 1)]
[:field {:name "city"} (line 2)]
[:field {:name "state_id", :ref (str "state_" (line 3))}]
[:field {:name "country_id", :ref "base.ch"}]]))
(defn render-state [state]
(html [:record {:id (str "state_" state), :model "res.country.state"}
[:field {:name "country_id", :ref "base.ch"}]
[:field {:name "name"} state]
[:field {:name "code"} state]]))
(defn generate-xml []
(let [rows (csv-data)]
(html [:openerp
[:data
(map render-state (get-states rows))
(map render-line rows)]])))
(defn get-states [csv-data]
(set (map (fn [a] (a 3)) csv-data)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment