Twitter::つぶやき
普段は Net::Twitter を使うのですが、
依存関係がすごいので、WWW::Mechanize だけを使ってやりました。
(香川大学図書館の情報をつぶやく、@kadai_lib を作りました。)
下は面倒につぶやけるperlプログラムです。(メモ代わり)
perl hoge.pl Hello,World
hoge.pl
#!/usr/bin/env perl use strict; use WWW::Mechanize; use Encode; # config my $username = "username"; my $password = "password"; my $url = "http://twitter.com/"; my $mech = WWW::Mechanize->new(); sub main { my $twit = $ARGV[0]; # access twtter $mech->get($url); #$mech->form_number(1); $mech->form_id('signin'); $mech->set_fields('session[username_or_email]'=>$username, 'session[password]'=>$password); my $res = $mech->submit; return if(!$mech->success); # twit &twit($twit); return; } sub twit { my $twit = shift @_; $twit = Encode::decode("utf8",$twit); #$mech->form_number(2); $mech->form_id('status_update_form'); $mech->set_fields('status'=>$twit); $mech->submit; return; } &main; 1;
11/24: formをnumberで取得してたので、idで取得するように変更しました。
(formのnumberが変わっていたので)
ref:
Perlモジュール/WWW::Mechanize - Walrus, Digit.
シェルスクリプト : レンタルサーバーさくらインターネットを使いこなす 中級HP作成講座