(ql:quickload '(:dexador :nyaml )) (defun dehash (value) (typecase value (list (mapcar 'dehash value)) (string value) (array (map 'list 'dehash value)) (hash-table (loop for k being the hash-keys in value using (hash-value v) collect (cons k (dehash v)))) (t value))) (defparameter +base-uri+ "https://github.com/OpenCageData/address-formatting/raw/master/conf/") (defun write-sexp (path value) (with-open-file (s path :direction :output :if-exists :supersede :if-does-not-exist :create :external-format :utf-8) (write value :stream s))) (defun convert (file &optional multi) (let* ((url (concatenate 'string +base-uri+ file)) (name (subseq file (1+ (or (position #\/ file :from-end t) -1)) (position #\. file :from-end t))) (data (nyaml:parse (dex:request url) :multi-document-p t)) (alist (dehash (cdr data)))) (write-sexp (format nil "~a.sexp" name) (if multi alist (car alist))) (format t "done~%"))) (defparameter +abbrev-uri+ "https://github.com/OpenCageData/address-formatting/raw/master/conf/abbreviations/~a.yaml") (defparameter +langs+ '("ca" "cs" "da" "de" "en" "es" "et" "eu" "fi" "fr" "hu" "it" "nl" "no" "pl" "pt" "ro" "ru" "se" "sk" "tr" "uk" "vn")) (defun convert-abbrevs () (write-sexp "abbrevs.sexp" (loop for lang in +langs+ for uri = (format nil +abbrev-uri+ lang) do (format t "~a.." lang) collect (cons lang (dehash (nyaml:parse (dex:request uri)))))) (terpri)) (defun convert-all () (convert-abbrevs) (loop for file in '("countries/worldwide.yaml" "country2lang.yaml" "county_codes.yaml" "state_codes.yaml") do (format t "Processing ~a.." file) do (convert file)) (convert "components.yaml" t))