Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 21st, 2012  |  syntax: None  |  size: 2.18 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/local/bin/gosh
  2. (use srfi-1)
  3. (use rfc.http)
  4. (use sxml.ssax)
  5. (use sxml.sxpath)
  6. (use file.util)
  7. (use rfc.uri)
  8. (use file.util)
  9. (define (img uri)
  10.   (receive
  11.         (uri-scheme user-info hostname port path query fragment)
  12.         (uri-parse uri)
  13.         (receive (dir file ext) (decompose-path path)
  14.           (receive (status head body) (http-get hostname path)
  15.                            (if (boolean? ext)
  16.                                  (with-output-to-file file (pa$ print body))
  17.                                  (with-output-to-file (string-append file "." ext) (pa$ print body)))))))
  18. (define (follow-get user)
  19.   (receive (status head body)
  20.                    (http-get "api.twitter.com"
  21.                                          (string-append "/1/friends/ids/" user ".xml"))
  22.                    (ssax:xml->sxml (open-input-string body) '())))
  23. (define (follower-get user)
  24.   (receive (status head body)
  25.                    (http-get "api.twitter.com"
  26.                                          (string-append "/1/followers/ids/" user ".xml"))
  27.                    (ssax:xml->sxml (open-input-string body) '())))
  28. (define (user-get id)
  29.   (receive (status head body)
  30.                    (http-get "api.twitter.com"
  31.                                          (string-append "/1/users/show.xml?id=" id))
  32.                    (ssax:xml->sxml (open-input-string body) '())))
  33. (define (main args)
  34.   (display ">> ")
  35.   (flush)
  36.   (let1 user (read)
  37.                 (display "cmd> ")
  38.                 (flush)
  39.                 (let1 cmd (read)
  40.                           (make-directory* (string-append (x->string user) "-" (x->string cmd)))
  41.                           (print "Maked...")(flush)
  42.                           (current-directory (string-append (x->string user) "-" (x->string cmd)))
  43.                           (print "In " (string-append (x->string user) "-" (x->string cmd))"...")(flush)
  44.                           (cond ((eq? cmd ':q)(exit))
  45.                                         ((eq? cmd ':follow)
  46.                                          (begin (print "Follow get")(flush)(solve (map (lambda(x)(cadr x)) ((sxpath "/id_list/ids/id")(follow-get (x->string user)))))))
  47.                                         ((eq? cmd ':follower)
  48.                                          (begin (print "Follower get")(flush)(solve (map (lambda(x)(cadr x)) ((sxpath "/id_list/ids/id")(follower-get (x->string user)))))))
  49.                                         (else (print "ERROR"))))))
  50. (define (solve lst)
  51.   (print "フォロ*ー数: "(length lst))
  52.   (let loop ((lst lst)(n 1))
  53.         (if (null? lst)
  54.           (print "Empty")
  55.           (let1 result ((sxpath "/user/profile_image_url/text()") (user-get (car lst)))
  56.                         (if (null? result)
  57.                           (print "Done")
  58.                           (begin (print "GET")
  59.                                          (print "["n"]Downloads..."(car result))
  60.                                          (img (car result))
  61.                                          (loop (cdr lst) (+ n 1))))))))