Chinaunix首页 | 论坛 | 博客
  • 博客访问: 438850
  • 博文数量: 161
  • 博客积分: 5005
  • 博客等级: 上校
  • 技术积分: 1090
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-20 16:38
文章分类

全部博文(161)

文章存档

2011年(21)

2010年(33)

2009年(89)

2008年(18)

我的朋友

分类:

2009-06-27 04:00:06

#!/usr/bin/perl -w


# Twitter -> Xiaonei status sync tool.

# Author: Feng Liu

# Version: 1.0

# Date: Tue Apr 21 23:06:40 +0000 2009


use utf8;
use Encode;
use LWP::Simple;
use HTML::Entities;

####################### Settings starts here #######################

# Set your base account information here. Don't show this to others!

my $twitter_account = '';
my $xiaonei_email = '';
my $xiaonei_passwd = '';

# some machine's wget is too old, so you may need to rebuild a newer

# version and indicate the path of your own wget here.

my $wget_cmd = 'wget';

# The program needs a log file for keeping the time of your last

# tweet. Otherwise you may get your xiaonei status updated to a same

# tweet. So please keep this file!

my $logfile = '/tmp/twxn.log';
######################## Settings ends here ########################


my $twitter_url = '' . $twitter_account . '.xml';
my $statuses = get($twitter_url);
my @lines = split /\n/, $statuses;
my $latest_text = $lines[5];
my $latest_time = $lines[3];

if ($latest_text =~ /<text>(.*)<\/text>/) {
    $status = $1;
};
$text = decode_entities($status);

# If the log file doesn't exist, create a new one.

if (!(-e $logfile)) {
    open LOG,"> /tmp/twxn.log" or die "ERROR: Cannot create log file.";
    close LOG;
    print "Created a new log file: $logfile\n";
}

open LOG, "< $logfile" || die "ERROR: Cannot open log file!";
$last_time = <LOG>;
close LOG;

if ($last_time ne $latest_time) {

    my $login_cmd = $wget_cmd . ' --no-proxy -O xiaoneilogin.log --post-data="email=' . $xiaonei_email . '&password=' . $xiaonei_passwd . '&autoLogin=true" --keep-session-cookies --save-cookies=xiaoneicookie ';

    my $post_cmd = $wget_cmd . ' --no-proxy -O xiaoneipost.log --post-data="c=' . $text . '" --keep-session-cookies --load-cookies=xiaoneicookie --referer=';

    system($login_cmd);
    system($post_cmd);
   
    open LOG, "> $logfile" || die "ERROR: Cannot open log file!";
    print LOG $latest_time;
    close LOG;
}

阅读(922) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~