Skip to content

Instantly share code, notes, and snippets.

@iyahoo iyahoo/cltrans.lisp
Created Sep 4, 2015

What would you like to do?
#|-*- mode:lisp -*-|#
exec ros -Q -- $0 "$@"
(unless (find-package :drakma)
(ql:quickload '(:drakma) :silent t))
(unless (find-package :cl-json)
(ql:quickload '(:cl-json) :silent t))
(unless (find-package :babel)
(ql:quickload '(:babel) :silent t))
(unless (find-package :cl-html5-parser)
(ql:quickload '(:cl-html5-parser) :silent t))
(defun respons-from (url &key method additional-headers parameters)
(babel:octets-to-string (drakma:http-request url :method method :additional-headers additional-headers :parameters parameters)))
(defun result-string (html)
(third (third (nth 3 html))))
(defun main (&rest argv)
(when argv
(let ((json (respons-from ""
:method :post
:parameters '(("grant_type" . "client_credentials")
("client_id" . "client_id")
("client_secret" . "client_secret")
("scope" . "")))))
(let* ((access-token (cdr (assoc :access--token (json:decode-json-from-string json))))
(auth (concatenate 'string "Bearer " access-token))
(html (respons-from ""
:method :get
:additional-headers `(("Authorization" . ,auth))
:parameters `(("from" . "en")
("to" . "ja")
("text" . ,(first argv))))))
(format t "~a~%"
(result-string (html5-parser:parse-html5 html :dom :xmls)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.