Changeset 34115 for lang/perl/misc/MyOA/tweet_feed.pl
- Timestamp:
- 06/24/09 10:17:20 (4 years ago)
- Files:
-
- 1 modified
-
lang/perl/misc/MyOA/tweet_feed.pl (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/misc/MyOA/tweet_feed.pl
r34114 r34115 6 6 use LWP::UserAgent; 7 7 8 my $db h = DBI->connect( 'DBI:mysql:myopenarchive:localhost:3306', 'user',9 'pass' );8 my $db_user = 'db_user'; 9 my $db_pass = 'db_pass'; 10 10 11 my $twitter_user = 'user'; 12 my $twitter_pass = 'pass'; 13 14 my $dbh = 15 DBI->connect( 'DBI:mysql:myopenarchive:localhost:3306', $db_user, $db_pass ); 11 16 $dbh->do("set names utf8"); 12 17 18 # tweet_counterにないデータ(新規投稿)を追加 13 19 $dbh->do( 14 20 "insert into tweet_counter … … 18 24 ); 19 25 26 # twitterへの投稿回数が少ないものからランダムに情報取得 20 27 my $sth = $dbh->prepare( 21 28 "select * from tweet_counter left join documents using(id) … … 24 31 ); 25 32 $sth->execute(); 33 26 34 my $document_info = {}; 27 35 while ( my $str = $sth->fetchrow_hashref ) { … … 31 39 } 32 40 41 # カウントアップ 33 42 $sth = $dbh->prepare("update tweet_counter set count=count + 1 where id=?"); 34 43 $sth->execute( $document_info->{id} ); 35 44 45 # タイトルと短縮URL取得 36 46 my $title = $document_info->{title}; 37 47 my $url = get_short_url( 38 48 "http://www.myopenarchive.org/documents/view/$document_info->{id}"); 39 49 50 # status整形 40 51 my $format = "[Featured on MyOA]%s %s"; 41 52 my $status = sprintf $format, $title, $url; 42 53 43 my $USER = 'user'; 44 my $PASSWORD = 'pass'; 54 # twitterへ投稿 45 55 my $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 ); 47 58 $ua->post( 'http://twitter.com/statuses/update.xml', { status => $status } ); 48 59 … … 52 63 my $rs = $ua->get("http://tinyurl.com/api-create.php?url=$url"); 53 64 return $rs->content; 54 55 65 } 56 57 exit 0;
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)