Twitter ãããã®ä½ãæ¹ Perl ç·¨ (1)2009-06-29
Twitter ãããã®ä½ãæ¹è§£èª¬ç¬¬ 1 å¼¾ãåææ¡ä»¶ã¨ãä¸æºåã¾ã§ã解説ãã¾ãã
ãããªã¨ããèªåã ã£ããããããããããä½ãã®ã«ï¼ã£ã¦ããæãããã£ã¦ãããªããªãä½ããªã人ãå¤ãã®ã§ã¯ãªãã§ããããï¼
ããã§ã¯ããã®ã¾ã¾åä½ãããµã³ãã«ãæ示ããäºã§ãTwitter ã®ããããä½ãæ¹æ³ã解説ãã¾ãã
Perl ã¨ã詳ãããªãã¦ããLinux ã®ç¥èãããç¨åº¦ããã°ãèªç±ã«ããããä½ããããã«ãªãã¯ãã§ãã
ã§ã¯ããããããããæ¬ç·¨ã§ãï¼
ã¾ããä»å¾ã®ããããä½æããã«ããã£ã¦ã¯ãå種è¨å®ããã¼ã¿ãªã©ãå¥ãã¡ã¤ã«ã«ä¿åããæ¹ããããããã®ã§ãããèªã¿æ¸ãã®ããããã¨ä½¿ãããããèæ ®ã㦠YAML ãæ¡ç¨ãã¾ãã
ã¾ãã¯ãããã® CPAN ã©ã¤ãã©ãªãå°å ¥ããã¨ããããã§ãã
åã¢ã¸ã¥ã¼ã«ã®ã¤ã³ã¹ãã¼ã«ä¸ã¯çµæ§æéããããã¾ãããæ°é·ã«å¾ ã¡ã¾ãããã
å種ãªãã·ã§ã³ã¯ãæå³ãç解ããä¸ã§ããã¦å¤ãããã¨ããªãéãå ¨ã¦ããã©ã«ã (ãã®ã¾ã¾ Enter) ã§æ§ãã¾ããã
â» CPAN ã®å©ç¨ã«ã¤ãã¦ä¸æãªç¹ãããã°ãããã£ãã¨ãããåç §ãã¦ä¸ããã
CPAN ã¢ã¸ã¥ã¼ã«ã®è¿½å ãå®äºããããã¨ããããç°¡åã«åä½ç¢ºèªããã¦ããã¾ãããã
ã¾ããconfig.yml ã¨ãããã¡ã¤ã«ãä½æãã¾ããå 容ã¯ä»¥ä¸ã®ãããªæãã§ãã
ãã¬ã¼ã³ããã¹ãã§ãã¹ã¯ã¼ããè¨è¼ãããã®ã§ããã¡ã¤ã«ã®æ¨©éã«ã¯æ°ãã¤ãã¦ä¸ããã
次ã«ãtwitbot.pl ã¨ãããã¡ã¤ã«ãä½æãã¾ããå 容ã¯ä»¥ä¸ã®ãããªæãã§ãã
ããã¾ã§æºåãåºæ¥ãããããããã«ã¹ã¯ãªãããèµ·åãã¾ãã
config.yml ã®æå®ãç¸å¯¾ãã¹ã«ãªã£ã¦ããã®ã§ãã«ã¬ã³ããã£ã¬ã¯ããªããèµ·åãã¦ä¸ããã
ã¨ã©ã¼ã«ãªããå®è¡ãå®äºããããTwitter ã® TL ã確èªãã¦ä¸ããã
ã¹ã¯ãªããããã®æ´æ°ãåæ ããã¦ãããæåã§ãã
ãããããã¾ã§åºæ¥ãã°ä¸æºåã¯å®äºã§ãã
ãããã次ãããå®éã®ããããä½ã£ã¦ããã¾ãã
åæ¸ã
Twitter ãããç¨åº¦ä½¿ã£ã¦ããã¨ãçªç¶è¦ãç¥ããã®ã¢ã«ã¦ã³ããã reply ãããã£ãããã¦ãããããããã ã¨ããäºã¯è¯ãããã¾ãããããªã¨ããèªåã ã£ããããããããããä½ãã®ã«ï¼ã£ã¦ããæãããã£ã¦ãããªããªãä½ããªã人ãå¤ãã®ã§ã¯ãªãã§ããããï¼
ããã§ã¯ããã®ã¾ã¾åä½ãããµã³ãã«ãæ示ããäºã§ãTwitter ã®ããããä½ãæ¹æ³ã解説ãã¾ãã
Perl ã¨ã詳ãããªãã¦ããLinux ã®ç¥èãããç¨åº¦ããã°ãèªç±ã«ããããä½ããããã«ãªãã¯ãã§ãã
ç®æ¨
ã ãã ãã¨ã¬ãã«ãä¸ããªããã以ä¸ã®ãããªããããä½ãäºãç®æ¨ã«ãã¾ãã- ãããããç¨æãããå®åæã®ä¸ããã©ã³ãã ã§ã¤ã¶ããããã
- ç¹å®ã®ã¯ã¼ãã«åå¿ãã¦ãreply ããããã
- ç¹å®ã® RSS ã®å 容ãã¤ã¶ããç¶ããããã
- ãããã«å¯¾ããã¡ãã»ã¼ã¸ã
GoogleYahoo ã§æ¤ç´¢ãã¦çµæãè¿ãããã
ç¨æãããã®
- ãããç¨ã®ã¢ã«ã¦ã³ã
- Perl 5.8.x ãåä½ãã Linux ãµã¼ã
- Perl ã® CPAN ãå©ç¨åºæ¥ã権é (é常㯠root 権é)
- perl ã¹ã¯ãªããã«ãã¹ãéãã¦å®è¡å¯è½ã«ãã権é
- cron ãè¨å®åºæ¥ã権é
- UTF-8 ã§ç·¨é/ä¿åãåºæ¥ãã¨ãã£ã¿
- ä¸è¨ãç解åºæ¥ãç¥è
æ¹é
- CPAN ã§å¯è½ãªäºã¯ãªãã¹ã CPAN ã§ãã
- DB ã¯ä½¿ãããã¼ã¿ã¯ãã¡ã¤ã«ã§æã¤
- ãããæãã§å³å¯ãªã¨ã©ã¼å¦çã¨ãã¯ããªã
ã§ã¯ããããããããæ¬ç·¨ã§ãï¼
ä¸æºå
Twitter ã®ããããä½æããã«ããã£ã¦ã¯ãå½ç¶ twitter ãµã¼ãã¨ã®ããã¨ããå¿ è¦ã«ãªãã®ã§ããããã®ããã® CPAN ã©ã¤ãã©ãªãå°å ¥ãã¾ããã¾ããä»å¾ã®ããããä½æããã«ããã£ã¦ã¯ãå種è¨å®ããã¼ã¿ãªã©ãå¥ãã¡ã¤ã«ã«ä¿åããæ¹ããããããã®ã§ãããèªã¿æ¸ãã®ããããã¨ä½¿ãããããèæ ®ã㦠YAML ãæ¡ç¨ãã¾ãã
ã¾ãã¯ãããã® CPAN ã©ã¤ãã©ãªãå°å ¥ããã¨ããããã§ãã
åã¢ã¸ã¥ã¼ã«ã®ã¤ã³ã¹ãã¼ã«ä¸ã¯çµæ§æéããããã¾ãããæ°é·ã«å¾ ã¡ã¾ãããã
å種ãªãã·ã§ã³ã¯ãæå³ãç解ããä¸ã§ããã¦å¤ãããã¨ããªãéãå ¨ã¦ããã©ã«ã (ãã®ã¾ã¾ Enter) ã§æ§ãã¾ããã
$ su - # perl -MCPAN -e shell cpan> install YAML::Tiny cpan> install Net::Twitter
â» CPAN ã®å©ç¨ã«ã¤ãã¦ä¸æãªç¹ãããã°ãããã£ãã¨ãããåç §ãã¦ä¸ããã
CPAN ã¢ã¸ã¥ã¼ã«ã®è¿½å ãå®äºããããã¨ããããç°¡åã«åä½ç¢ºèªããã¦ããã¾ãããã
ã¾ããconfig.yml ã¨ãããã¡ã¤ã«ãä½æãã¾ããå 容ã¯ä»¥ä¸ã®ãããªæãã§ãã
username: "twitter_user_name" password: "twitter_password"ããã§ã¯ãTwitter ã§ä½¿ç¨ããã¢ã«ã¦ã³ãã®ã¦ã¼ã¶åã¨ãã¹ã¯ã¼ããè¨è¿°ãã¦ããã¾ãã
ãã¬ã¼ã³ããã¹ãã§ãã¹ã¯ã¼ããè¨è¼ãããã®ã§ããã¡ã¤ã«ã®æ¨©éã«ã¯æ°ãã¤ãã¦ä¸ããã
次ã«ãtwitbot.pl ã¨ãããã¡ã¤ã«ãä½æãã¾ããå 容ã¯ä»¥ä¸ã®ãããªæãã§ãã
#!/usr/bin/perl use strict; use warnings; use YAML::Tiny; use Net::Twitter; my $config = (YAML::Tiny->read('config.yml'))->[0]; my $twit = Net::Twitter->new(username => $config->{'username'}, password => $config->{'password'}); $twit->update('Perl ãã Twiitter ãæ´æ°ãããã¹ãã§ããã¼');ããã UTF-8 ã§ä¿åããå®è¡å±æ§ãä¸ãã¾ããperl ã®ãã¹ã¯ç°å¢ã«åããã¦ä¿®æ£ãã¦ä¸ããã
ããã¾ã§æºåãåºæ¥ãããããããã«ã¹ã¯ãªãããèµ·åãã¾ãã
config.yml ã®æå®ãç¸å¯¾ãã¹ã«ãªã£ã¦ããã®ã§ãã«ã¬ã³ããã£ã¬ã¯ããªããèµ·åãã¦ä¸ããã
$ ./twitbot.pl
ã¨ã©ã¼ã«ãªããå®è¡ãå®äºããããTwitter ã® TL ã確èªãã¦ä¸ããã
ã¹ã¯ãªããããã®æ´æ°ãåæ ããã¦ãããæåã§ãã
ãããããã¾ã§åºæ¥ãã°ä¸æºåã¯å®äºã§ãã
ãããã次ãããå®éã®ããããä½ã£ã¦ããã¾ãã
ã«ãã´ãª: Development ã¿ã°: twitter perl