Created
September 3, 2013 13:00
-
-
Save ayato-p/6423583 to your computer and use it in GitHub Desktop.
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
#!/usr/local/bin/gosh | |
(use rfc.http) | |
(use rfc.uri) | |
(use rfc.json) | |
(use net.twitter) | |
(define *cred* (make <twitter-cred> | |
:consumer-key "XXXX" | |
:consumer-secret "XXXX" | |
:access-token "XXXX" | |
:access-token-secret "XXXX")) | |
;;http://ja.wikipedia.org/w/api.php?action=query&list=random&format=xml | |
(define (wikipedia-random) | |
(let1 jsonp | |
(receive (status head body) | |
(http-get "jp.wikipedia.org" | |
(string-append "/w/api.php" | |
"?action=query" | |
"&list=random" | |
"&rnnamespace=0" | |
"&format=json")) | |
(parse-json-string | |
(string-scan body "</html>" 'after))) | |
(let1 param (ref (cdadar jsonp) 0) | |
(let ((id (assoc-ref param "id")) | |
(title (assoc-ref param "title"))) | |
(values id title))))) | |
(define (get-wikipedia-url id) | |
(let1 jsonp (receive (status head body) | |
(http-get "jp.wikipedia.org" | |
(string-append "/w/api.php" | |
"?action=query" | |
"&pageids=" (number->string id) | |
"&prop=info" | |
"&inprop=url" | |
"&format=json")) | |
(parse-json-string | |
(string-scan body "</html>" 'after))) | |
(assoc-ref (car (cdadar jsonp)) "fullurl"))) | |
(define (main args) | |
(receive (id title) | |
(wikipedia-random) | |
(twitter-update *cred* | |
(string-join `(,title ,(get-wikipedia-url id)) | |
"\n")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment