Rubyã§TwitterBotãã¤ãã£ã¦ãµã¼ãã¼ã«ã¢ããããã
ãªããããã²ããã¶ãã§ãã
ä½ããã¦ããã¨ããã¨ã
誰ã§ãã§ããTwitter Botã®ä½ãæ¹â人æ°ãã£ã©ã«ã¤ã¶ãããã
- ä½è : é家çµæ¸ç 究æ
- åºç社/ã¡ã¼ã«ã¼: ã¤ã¼ã°ã«ãããªã·ã³ã°
- çºå£²æ¥: 2010/07/23
- ã¡ãã£ã¢: åè¡æ¬ï¼ã½ããã«ãã¼ï¼
- è³¼å ¥: 7人 ã¯ãªãã¯: 569å
- ãã®ååãå«ãããã° (15件) ãè¦ã
ã©ããã«ãã¨ããã¨ããã®æ¬ã§æ±ããã¦ãè¨èªãRubyã¨ããã¨ãããï¼èªåã®è½å許容éçã«ï¼å¤§ãã«ã§ãã
â¦â¦ãªãã§ãã®æã«åãã§ã¾ãè¨èªãå¢ãããã¨ããã®ãï¼
ã誰ã§ãã§ããTwitterBotã®ä½ãæ¹ãã«ã¤ãã¦
ã¨ããã¨ããã§ãã®æ¬ã«ä»ãã¦ãã£ããã¨ã説æã§ãã
ãã®æ¬ã¯ã
- èªåã®PCã«Rubyãã¤ã³ã¹ãã¼ã«ã
- Windowsã®ã¿ã¹ã¯ã¹ã±ã¸ã¥ã¼ã©ãã¿ã¹ã¯ã§ãããèµ·åãã
- Twitterã«äºãç¨æãã¦ãããè¨èãèªåçã«ã¢ãããã
botãä½ããã¨ãç®çã¨ãã¦ãã¾ãã
ã¤ã¾ããbotãåããã¦ãéã¯ãã£ã¨èªåã®PCãèµ·åãã£ã±ãªãããããã«ã¤ãªãã£ã±ãªãã«ãã¦ãããã°ãªãã¾ããã
ããèªåãèµ·ãã¦ãéã ãèµ·åãããbotã§ããã¨ããæ¹åæ§ããªããããããªãã§ãã管ç人ã¨botã®ã©ãã©ãå棲çæ´»ï¼ï½ï½ãã¸ãªï¼ スカーレッドライダーゼクスï¼ã®æ¼åºã§ããï¼
â¦â¦ä¸è¿·è¨ã¯ããã¨ãã¦ã
ããããããã§ããã®æ¬ãåèã«åºæ¥ä¸ããã®ã¯ããã¾ã§èªåã®PCãTwitterBotãµã¼ãã¨ãã¦ä½¿ç¨ããBotã§ãã
ããã大äºã
ã¤ãã£ãRubyã¹ã¯ãªããããµã¼ãã§ä½¿ç¨ããããã«ããã®ï¼
ç§ãæ®æ®µããããã¢ãããã¦ä½¿ã£ã¦ãã®ã¯ãããã¤ã³ã¿ã¼ãããã®ã¬ã³ã¿ã«ãµã¼ãã®ã¹ã¿ã³ãã¼ããã©ã³ã§ãã
ã¹ã¿ã³ãã¼ãã§ã¯ãµã¼ãã«Rubyãã¤ã³ã¹ãã¼ã«ããã¦ãã¾ãã®ã§ãä¸è¦æ¬ãåèã«ä½ã£ãã¹ã¯ãªããã使ãããããªæ°ããã¾ããããã§ãããã
ãªããªãæ¬ã®ã¹ã¯ãªããã¯å
¨ã¦ãtwitter_oauthãã¨ããã©ã¤ãã©ãªã使ç¨ãã¦ããããã®ã©ã¤ãã©ãªããããã¤ã³ã¿ã¼ãããã®ãµã¼ãã«ã¯ã¤ã³ã¹ãã¼ã«ããã¦ããªãããã§ãï¼2010å¹´7æç¾å¨ï¼ã
â¦â¦éã«è¨ãã°ãå¿
è¦ãªã©ã¤ãã©ãªãRubyã¹ã¯ãªããã¨ä¸ç·ã«ã¢ããããã°ä½¿ããã¯ãã
ã¨ããããã§ãããããã¨ããã¾ããã
- ã¹ã¯ãªããã«åºã¦ãããrequire 'rubygems'ãã¨ãã1æã¯ï¼ä»ãã¦ã³ã¡ã³ãã¢ã¦ãã
- ã³ãã³ãããã³ããã§ãgem fetch twitter_oauthãã¨å ¥åãã¦ãtwitter_oauth.gemãã¨ããã©ã¤ãã©ãªããã¦ã³ãã¼ããï¼gemã£ã¦ã®ãããåãããªããã§ãããããå ¥åããã¨ååã®ã©ã¤ãã©ãªããã¦ã³ãã¼ããã¦ãããããã§ãï¼
- twitter_oauth.gemã®æ¡å¼µåãã.tarãã«å¤æ´ãã¦è§£åãâãtwitter_oauth-0.4.2ããã©ã«ããã§ããï¼æ°åã¯éãããããã¾ããï¼ã
- 解åããä¸ããããã«ãdata.tar.gzãã¨ãããã¡ã¤ã«ãæ¢ããããã解åãâãdataããã©ã«ããã§ããã
- 解åãããdataããã©ã«ãå ãããlibãã¨ãããã©ã«ããæ¢ãããã®ä¸ã«ãããtwitter_oauth.rbããã¡ã¤ã«ã¨ãtwitter_oauthããã©ã«ãã使ç¨ãããRubyã¹ã¯ãªããã¨åãæã«è²¼ãä»ããã
以ä¸ããoauthããjsonããmime-typesãåã©ã¤ãã©ãªãï¼ãï¼ãç¹°ãè¿ãã¦ãã¦ã³ãã¼ãããè²¼ãä»ããã
ããã§ã¨ããããPCä¸ã§ã¯åãã¾ããï¼
â¦â¦ãã«ã§ããã¼ï¼
ãããã¤ã³ã¿ã¼ãããã§Rubyã¹ã¯ãªããã使ãã«ã¯
以ä¸ã®ãµã¤ãæ§ãå
¨é¢çã«åèã«ããã¦ããã ãã¾ããã
http://morio-dev.seesaa.net/article/134038083.html
ã¾ãã¯ä¸ã¤ãã«æãããã¦ããããRubyã¹ã¯ãªããã®æ¡å¼µåã.rbãã.cgiã«å¤æ´ãã¦ãã¼ããã·ã§ã³ã755ã«ãããæ¹æ³ã§ãã£ã¦ã¿ã¾ããã
ããæ¡å¼µåãå¤æ´ããããã¼ããã·ã§ã³å¤æ´ãããããã¹ã¯ãªããã¯èªä½ããbotã¹ã¯ãªããã ãã§ãã
ã¤ãã£ãRubyã¹ã¯ãªããããµã¼ãã§ä½¿ç¨ããããã«ããã®ï¼
ãã®ï¼ã¨ã¯éã®ã¢ããã¼ããSSHã§ãµã¼ãå´ã«å¿
è¦ãªã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«ããæ¹æ³ã§ãã
ãããã¤ã³ã¿ã¼ãããã¯ã¹ã¿ã³ãã¼ããã©ã³ä»¥ä¸ã§TELNETãSSHã使ãã¾ããããããã¨ãµã¼ãå´ã®Rubyã«å
¥ã£ã¦ãªãã©ã¤ãã©ãªãã¦ã¼ã¶ã¼ãã£ã¬ã¯ããªï¼ã«ã¤ã³ã¹ãã¼ã«ãã¦ä½¿ããã¨ãã§ããããã§ãã
使ç¨ããSSHã¯ã©ã¤ã¢ã³ãã¯ãã¡ãâ
http://yebisuya.dip.jp/Software/PuTTY/
åèã«ããã®ã¯ãã¡ãâ
さくらのレンタルサーバーに RubyGems をインストールする手順 - Google App Engine+Pythonで脱プログラミング初心者を目指す日記
ãªãããã°è¨äºã§ã¯éä¸ã§viã¨ãã£ã¿ã«ããç·¨éãããã¾ãããç§ãã¤ã³ã¹ãã¼ã«ãã1.3.7ã§ã¯
set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin /usr/X11R6/bin)
â
set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin /usr/X11R6/bin /home/User/bin)
ã®æ¸ãæãã¯å¿ è¦ããã¾ããã§ããããªãããï¼HOMEã¨ããªã£ã¦ã¾ããã
åèã«ããè¨äºã®ã¨ããã«ãã£ã¦ãã°å¤§ä½ééããªãGEMãã¤ã³ã¹ãã¼ã«ã§ãããã§ãããç§ããã£ãã¨ãã¯éä¸ã§ã¨ã©ã¼ã³ã¼ãåºã¦æ¢ã¾ãã¾ãããGEMã®ã¤ã³ã¹ãã¼ã«å ´æã¯ã¦ã¼ã¶ã¼ãã£ã¬ã¯ããªã®ãªãã®ä¸ç®æãã¨æ±ºãã¦ãã¯ããªã®ã«ãåæã«ã«ã¼ãã«ã¤ã³ã¹ãã¼ã«ãã«è¡ã£ã¦æããã¦ã¾ããããããæããããã
ã§ããã®ã¨ã©ã¼ã³ã¼ããåºãã¨ãã«åèã«ããã®ããã¡ãâ
さくらサーバーに gem をインストールする際に「chown/chgrp: Operation not permitted」とエラーが出た場合 - make world
ãã使ç¨ããUNIXã³ãã³ã
ã¤ã³ã¹ãã¼ã«ã«ããã£ã¦ã¯ä»¥ä¸ã®ã³ãã³ãããããã¡ã¾ããã
pwd | ç¾å¨ã®ãã£ã¬ã¯ããªã®å ´æã絶対ãã¹ã§è¡¨ç¤ºãã |
ls | ãã£ã¬ã¯ããªã®æ å ±ã表示ãããããããã«ãã®ãã£ã¬ã¯ããªã«ãªãã¨ãããã¡ã¤ã«ããµããã£ã¬ã¯ããªããããã表示ãããã©ãã®ãã£ã¬ã¯ããªãæå®ãã¦ãªãæã¯ã«ã¬ã³ããã£ã¬ã¯ããªã®æ å ±ã表示ã |
cd | ãã§ã³ã¸ãã£ã¬ã¯ããªããã£ã¬ã¯ããªã®ç§»åã |
è¶ åºæ¬ã§ããåºæ¬ã ãã©ããããã£ã¦ã¡ã¢ãã¦ãããªãã¨å¿ãã¦ãã¾ãã
twitter_oauthã©ã¤ãã©ãªã
GEMãã¤ã³ã¹ãã¼ã«ã§ãããã次ã¯twitter_oauthãã¤ã³ã¹ãã¼ã«ãããããæé èªä½ã¯PCã«ã¤ã³ã¹ãã¼ã«ããæã¨å¤ããã¾ããã
%gem install twitter_oauth
ã§ãµã¤ã¼ã«ã¤ã³ã¹ãã¼ã«ãã¦ããã¾ãããâ¦â¦ããããã¡ãã£ã¨ãã®ã¸ãè¨æ¶ãææ§ã§ãã
ããã¾ã§ããã°ããã¨ã¯PCã®ã³ãã³ãããã³ããããã®å®è¡ã¨åãããã«ããruby test.rbãã¨ãããã¨å®è¡ãã¦ããã¾ãã
cronã§å©ãæ¹æ³ã¯ã¾ãä»åº¦æ¢ãã¾ããã¾ãã¯ã¹ã¯ãªããæ¸ããªãã¨ã
æåã³ã¼ã
ããã§ä¸ã¤ãã¡ã¢ã
ãããã¤ã³ã¿ã¼ãããã®ãµã¼ãã¼ã¯EUCã³ã¼ãã§ããã®ã§ãã¹ã¯ãªãããã¡ã¤ã«ã¯EUCã§ä½ãã®ãããããã§ãããruby -Ks ã¹ã¯ãªããåãã¨ãããªãã¦ãæååãããªãã§ã¡ããã¨åãã¦ããã¾ããããã PCã§ãã¹ãããæï¼ï¼ã³ãã³ãããã³ããã§åããæï¼ã¯Shift_JISã§ãªãã¨ãããªãã®ã§ããµã¼ãã¼ã«ã¢ããããæã«EUCã«å¤æããã®ãããããã