Show
Ignore:
Timestamp:
06/24/09 10:17:20 (4 years ago)
Author:
omoon
Message:

コメントなど追加。

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/misc/MyOA/tweet_feed.pl

    r34114 r34115  
    66use LWP::UserAgent; 
    77 
    8 my $dbh = DBI->connect( 'DBI:mysql:myopenarchive:localhost:3306', 'user', 
    9     'pass' ); 
     8my $db_user = 'db_user'; 
     9my $db_pass = 'db_pass'; 
    1010 
     11my $twitter_user = 'user'; 
     12my $twitter_pass = 'pass'; 
     13 
     14my $dbh = 
     15  DBI->connect( 'DBI:mysql:myopenarchive:localhost:3306', $db_user, $db_pass ); 
    1116$dbh->do("set names utf8"); 
    1217 
     18# tweet_counterにないデータ(新規投稿)を追加 
    1319$dbh->do( 
    1420    "insert into tweet_counter 
     
    1824); 
    1925 
     26# twitterへの投稿回数が少ないものからランダムに情報取得 
    2027my $sth = $dbh->prepare( 
    2128    "select * from tweet_counter left join documents using(id) 
     
    2431); 
    2532$sth->execute(); 
     33 
    2634my $document_info = {}; 
    2735while ( my $str = $sth->fetchrow_hashref ) { 
     
    3139} 
    3240 
     41# カウントアップ 
    3342$sth = $dbh->prepare("update tweet_counter set count=count + 1 where id=?"); 
    3443$sth->execute( $document_info->{id} ); 
    3544 
     45# タイトルと短縮URL取得 
    3646my $title = $document_info->{title}; 
    3747my $url   = get_short_url( 
    3848    "http://www.myopenarchive.org/documents/view/$document_info->{id}"); 
    3949 
     50# status整形 
    4051my $format = "[Featured on MyOA]%s %s"; 
    4152my $status = sprintf $format, $title, $url; 
    4253 
    43 my $USER     = 'user'; 
    44 my $PASSWORD = 'pass'; 
     54# twitterへ投稿 
    4555my $ua = LWP::UserAgent->new( agent => 'Bot-TweetFeed', keep_alive => 1 ); 
    46 $ua->credentials( 'twitter.com:80', 'Twitter API', $USER, $PASSWORD ); 
     56$ua->credentials( 'twitter.com:80', 'Twitter API', $twitter_user, 
     57    $twitter_pass ); 
    4758$ua->post( 'http://twitter.com/statuses/update.xml', { status => $status } ); 
    4859 
     
    5263    my $rs  = $ua->get("http://tinyurl.com/api-create.php?url=$url"); 
    5364    return $rs->content; 
    54  
    5565} 
    56  
    57 exit 0;