0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Twitter、フォロイー・フォロワーのアイコンを保存

Posted at

 問題点

  • OAuth認証していないせいかすぐにAPI制限にかかる。
  • API制限にかかるので全てのフォロイー・フォロワーのアイコンを保存できない。
  • 保存ができているのは150枚前後。
img-twitter.scm
# !/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))))))))
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?