Last active
August 29, 2015 14:11
-
-
Save lsgrep/f1498efb5a9ea0a371af to your computer and use it in GitHub Desktop.
lichess 中文翻译成维语
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
;;(:require [org.httpkit.client :as httpkit]) | |
;;(:require [clojure.java.io :as io]) | |
;;(:require [net.cgrand.enlive-html :as html]) | |
(defn get-raw-translation-result [src-text ] | |
(apply (comp first :content ) (html/select (html/html-snippet | |
(:body (http/post "http://tilmach.net" | |
{:form-params {:Source src-text}}))) [:textarea#Target]))) | |
(defn translate [src] | |
(.trim (get-raw-translation-result src))) | |
;; testing translate function | |
(translate "你好") | |
(def ^:dynamic lichess-zh-url "https://raw.githubusercontent.com/ornicar/lila/master/conf/messages.zh") | |
(def temp-file (java.io.File/createTempFile "lichess-ug" ".txt")) | |
(.getAbsolutePath temp-file) | |
(with-open [rdr (io/reader lichess-zh-url) | |
wr (io/writer temp-file) | |
] | |
(binding [*out* wr] | |
(doseq [line (line-seq rdr)] | |
(println line ) | |
(println (translate (second (.split line "=")))) | |
))) | |
(slurp temp-file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment