Skip to content

Instantly share code, notes, and snippets.

@alexpw
Last active December 20, 2015 11:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexpw/6125634 to your computer and use it in GitHub Desktop.
Save alexpw/6125634 to your computer and use it in GitHub Desktop.
parse metar xml
(ns metar.core
(:require [clojure.zip :as z]
[clojure.xml :as x]
[cheshire.core :as j]))
(defn metar-zipper
[url]
(-> url x/parse z/xml-zip z/children))
(defn tag-kv
[nodes]
(when (vector? nodes)
(reduce
(fn [xs {:keys [tag content]}]
(assoc xs tag
(if (map? (first content))
(tag-kv content)
(first content))))
{}
nodes)))
(defn parse-metar
[url]
(->> (metar-zipper url)
(filterv #(= :data (:tag %)))
first
:content
(mapv #(tag-kv (% :content)))))
(defn -main
[& args]
(let [url "http://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=PHTO&hoursBeforeNow=4"]
(parse-metar url)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment