Created
July 26, 2012 08:11
-
-
Save psihy/3180908 to your computer and use it in GitHub Desktop.
Get random words using Wikipedia API and BiwaScheme
This file contains hidden or 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
<!-- BiwaScheme 0.6.1 --> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>Powered by BiwaScheme</title> | |
<style> | |
input#fire { width: 50px; height: 24px; font-size: 14px; } | |
</style> | |
</head> | |
<body> | |
<form> | |
<input id="fire" type="button" value="fire!" /> | |
</form> | |
<div id="bs-console" /> | |
<script type="text/javascript" src="./biwascheme.js"> | |
(define (assoc-ref xs key) | |
(cdr (assoc key xs))) | |
(define (join-query qs) | |
(string-join (map (lambda (x) (string-join x "=")) qs) "&")) | |
(add-handler! ($ "#fire") "click" | |
(lambda (e) | |
(let ((uri "http://ja.wikipedia.org/w/api.php") | |
(opt `(("action" "query") | |
("list" "random") | |
("rnnamespace" "0") | |
("rnlimit" ,(number->string 20)) | |
("format" "json")))) | |
(let ((result (json->sexp (receive-jsonp (string-append uri "?" (join-query opt)))))) | |
(map print | |
(map (lambda (x) (assoc-ref x "title")) | |
(assoc-ref (assoc-ref result "query") "random"))))))) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment