- #!/usr/local/bin/gosh
- (use srfi-1)
- (use rfc.http)
- (use sxml.ssax)
- (use sxml.sxpath)
- (use file.util)
- (use rfc.uri)
- (use file.util)
- (define (img uri)
- (receive
- (uri-scheme user-info hostname port path query fragment)
- (uri-parse uri)
- (receive (dir file ext) (decompose-path path)
- (receive (status head body) (http-get hostname path)
- (if (boolean? ext)
- (with-output-to-file file (pa$ print body))
- (with-output-to-file (string-append file "." ext) (pa$ print body)))))))
- (define (follow-get user)
- (receive (status head body)
- (http-get "api.twitter.com"
- (string-append "/1/friends/ids/" user ".xml"))
- (ssax:xml->sxml (open-input-string body) '())))
- (define (follower-get user)
- (receive (status head body)
- (http-get "api.twitter.com"
- (string-append "/1/followers/ids/" user ".xml"))
- (ssax:xml->sxml (open-input-string body) '())))
- (define (user-get id)
- (receive (status head body)
- (http-get "api.twitter.com"
- (string-append "/1/users/show.xml?id=" id))
- (ssax:xml->sxml (open-input-string body) '())))
- (define (main args)
- (display ">> ")
- (flush)
- (let1 user (read)
- (display "cmd> ")
- (flush)
- (let1 cmd (read)
- (make-directory* (string-append (x->string user) "-" (x->string cmd)))
- (print "Maked...")(flush)
- (current-directory (string-append (x->string user) "-" (x->string cmd)))
- (print "In " (string-append (x->string user) "-" (x->string cmd))"...")(flush)
- (cond ((eq? cmd ':q)(exit))
- ((eq? cmd ':follow)
- (begin (print "Follow get")(flush)(solve (map (lambda(x)(cadr x)) ((sxpath "/id_list/ids/id")(follow-get (x->string user)))))))
- ((eq? cmd ':follower)
- (begin (print "Follower get")(flush)(solve (map (lambda(x)(cadr x)) ((sxpath "/id_list/ids/id")(follower-get (x->string user)))))))
- (else (print "ERROR"))))))
- (define (solve lst)
- (print "フォロ*ー数: "(length lst))
- (let loop ((lst lst)(n 1))
- (if (null? lst)
- (print "Empty")
- (let1 result ((sxpath "/user/profile_image_url/text()") (user-get (car lst)))
- (if (null? result)
- (print "Done")
- (begin (print "GET")
- (print "["n"]Downloads..."(car result))
- (img (car result))
- (loop (cdr lst) (+ n 1))))))))