ãã®è¨äºã¯ãã¡ããã¡ãå¤ãã§ãï¼å¥ã®æ¹æ³ã§ï¼oAuthã«å¯¾å¿ããbotãä½ã£ã¦ãã ããï¼google:twitter bot oAuth
ä»æ¥ã¯Twitterã®ç°¡åãªbotãä½ã£ã¦ã¿ã¾ãã
ä½ããã®
ç¾å¨ã®UNIXã¿ã¤ã ãé
ä¿¡ãããunixtimebotãä½ãã¾ãã
æ¢ã«å®æãããã®ã以ä¸ã®URLã§åãã¦ãã¾ã(飽ãããé
ä¿¡ãæ¢ã¾ãããããã¾ãã)ã
ããªãã¯ãã®botãfollowãããã¨ã«ãã£ã¦ã常ã«UNIXã¿ã¤ã ãæèããªããæ®ãããã¨ãã§ãã¾ãã
æ¹é
Rubyã使ãã¾ãã
ç´æ¥Twitterã®APIãå©ãã®ã§ã¯ãªããRubyGemsããã©ã¤ãã©ãªãåã£ã¦ãã¦ããã使ã£ã¦ã¢ã¯ã»ã¹ãã¾ãã
Twitterã«ã¢ã¯ã»ã¹ã§ããgem
Twitterã«ã¢ã¯ã»ã¹ããããã®gemã¯ãã¡ãã£ã¨æ¢ããã ãã§ãããã ãããã¾ããã
- Twitter4R
- Rubytter
ä»ã«ãããããããããã§ãããä»åã¯Rubytterã使ãã¾ãã
gemã®Twitterã¯èªè¨¼ã«OAuthã®ã¿ãµãã¼ãããã¦ãã¦ã使ãã«ããã®ã§ããã¾ããã*1
Twitter4Rã¯ååãã±ã£ã¨ããªãæãã ã£ãã®ã§ãRubytterã使ãã¾ãã
Rubytterãã¤ã³ã¹ãã¼ã«ãã¾ãã
sudo gem install rubytter
ã¤ãã§ã«ãbotç¨ã®ã¢ã«ã¦ã³ããåãã¾ãã
Gmailã®ã¢ã«ã¦ã³ããæã£ã¦ãã人ã¯ãã¨ã¤ãªã¢ã¹ã使ã£ã¦ç»é²ããã¨ä¾¿å©ã§ãã
foo@gmail.comã®äººã¯ãfoo+bar@gmail.comã¨ãã§ç»é²ãã¦ããã¨ããã¤ã使ã£ã¦ããã¢ãã¬ã¹ã§botå®ã®ã¡ã¼ã«ãåä¿¡ã§ãã¾ãã
ã¢ã«ã¦ã³ããåãããããããã£ã¼ã«ãå
¥ãã¦ããã¾ãããã
ããã§æºåã§ãã¾ããã
ãã¨ã¯ä½ãã ãã§ãã
ãã®åã«ããã¥ã¡ã³ããèªãã
gemã§ã¤ã³ã¹ãã¼ã«ããã©ã¤ãã©ãªã®ããã¥ã¡ã³ãããã©ã¦ã¶ã§èªãã¨ä¾¿å©ã§ãã
% gem server Starting gem server on http://localhost:8808/
ããã§ãhttp://localhost:8808/ã«ãã©ã¦ã¶ã§ã¢ã¯ã»ã¹ããã¨ãããã¥ã¡ã³ããèªãã¾ãã
ä»åã¯å¤§ãããã¨ãããªãã®ã§å¿
è¦ãªãããããã¾ãããããã®ãã¡å¿
è¦ã«ãªãã¯ãã§ãã
ä½ãã¾ããã
unixtimebotã®ä»æ§ã¯ä»¥ä¸ã®ããã«ãã¾ãã
- ä¸å®æéãã¨ã«unixã¿ã¤ã ãé ä¿¡ãã
- replyã¨ãã¯ç¹ã«è¦ãªã
ä½ãã¾ããã
#! /usr/bin/env ruby require 'rubygems' require 'rubytter' raise "usage: ./unixtimebot.rb ID PASSWORD" unless ARGV.size == 2 client = Rubytter.new(*ARGV) loop do now = Time.now.to_i if now % 1000 == 0 puts now client.update now end sleep 1 end
èµ·åããã¨ãTwitterã«ãã°ã¤ã³ãã¦ãããã®ããæéã«ãªãã¨æå ±ãæ稿ãã¾ãã
ç¾å¨ã®UNIXã¿ã¤ã ã1000ã§å²ãåããã¨ãã«æå ±ãåºãããã«ãã¦ã¿ã¾ããã
åããã¦ã¿ã¾ã(ID, PASSWORDã«ã¯ãã£ãåã£ãã¢ã«ã¦ã³ãã®IDã¨ãã¹ã¯ã¼ããå ¥ãã¾ã)ã
% ./unixtimebot ID PASSWORD 1239033000
åãã¾ãããããã¯ä¾¿å©ã§ãã
ç´°ãããã¨
ä»åã¯1000ç§ãã¨ã«è¡¨ç¤ºãã¦ã¿ã¾ãããã調åã«ä¹ã£ã¦10ç§ãã¨ã¨ãã«ããã¨ãã¿ã¤ã ã©ã¤ã³ãbotã®çºè¨ã§åãå°½ãããã¦ããã¸ããã£ã¨ãããããè²´éãªãããã¯ã¼ã¯è³æºã浪費ãã¦ãã¾ãã®ã§ãæ°ãã¤ãã¦ãã ããã
ã¾ãããã®ã¾ã¾ã§ã¯Twitterã¨ãã¾ãéä¿¡ã§ããã«ä¾å¤ãèµ·ããã¨ããã°ã©ã ãåæã«çµäºãã¦ãã¾ãã®ã§ã対å¿ããå¿ è¦ãããã¾ãã
% while [ 1 ]; do; ./unixtimebot.rb ID PASSWORD;sleep 10; done
ãããã£ã¦èµ·åãã¦ããã¨ãä½ãä¾å¤ãèµ·ãã¦çµäºãã¦ãã¾ãåæã«ç«ã¡ä¸ããã¾ãã
ãããã人ã¯ã¡ããã¨ä¾å¤å¦çãã¾ãããã
ã¾ã¨ã
ä»åã¯ã¨ã¦ãç°¡åãªãã®ãä½ãã¾ããããã©ã®ããã«botãä½ã£ã¦ããã®ããåãã£ã¦ããã ãããã¨æãã¾ãã
ããã§çµããã ã¨ã²ã©ãæããªã®ã§ã次åã¯ãbotã¨ä¼è©±ãã¦ã¿ããã¨æãã¾ãã
次åãTwitterã®botãä½ã£ã¦åéãå¢ãããï¼ï¼ï¼ããã楽ãã¿ã«ï¼ï¼ï¼ï¼ï¼
追è¨
id:tsupoããã«è¨è¿°ãåããã«ããã¨ã®ææãé ããã®ã§ä¸é¨ä¿®æ£ãã¾ããã
ãããã¨ããããã¾ããã
*1:追è¨: twitter gemã§ãBASICèªè¨¼ã使ããããã«ãªã£ãããã§ãã [http://d.hatena.ne.jp/shokai/20090418/1240057250:title]