Twitter -> Renren status sync tool
虽然说目前网上已经有不少twitter信息同步至人人网的服务,但毕竟要把账号密码提交给别的网站,安全系数大大降低
所以还是一直在使用自己的服务器来做twitter的同步
但是淫淫网总是更新些莫名其妙的东西,所以我的更新程序也停了很长一阵子
闲来无事,便尝试着更新一下,觉得似乎也可以发布了,给更多想将twitter同步至淫淫网的朋友一个新的选择
代码是用perl编写的,推荐放在支持perl的linux主机中,并且确保linux帐户有权限运行wget,然后设置计划任务每n分钟运行一次既可
注:代码原作者为Feng Liu,我只是在他的基础上做更新而已
点击下载代码:twitter2renren
Update:
v1.5.1 – 修复了一个代码的bug,会导致提取到的check value不正确
#!/usr/bin/perl -w # Twitter -> Xiaonei status sync tool. # Version: 1.5.1 # Date 2010/07/26 # Original Author: Feng Liu <liufeng@cnliufeng.com> # Updated by Rui Fu <freelz@gmail.com> 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 = 'twxn.log'; ######################## Settings ends here ######################## my $twitter_url = 'http://twitter.com/statuses/user_timeline/' . $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,"> 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_text = <LOG>; close LOG; #ignore the direct reply if ($latest_text =~ /<text>@(.*)<\/text>/) { $last_text = $latest_text; } if ($last_text ne $latest_text) { if ($latest_text ne "") { my $login_cmd = $wget_cmd . ' --no-proxy -O renrenlogin.log --post-data="email=' . $xiaonei_email . '&password=' . $xiaonei_passwd . '&isplogin=true&origURL=http://www.renren.com/Home.do&domain=renren.com" --keep-session-cookies --save-cookies=renrencookie http://passport.renren.com/PLogin.do'; system($login_cmd); #get the check value open CHECKFILE, "< renrenlogin.log" || die "ERROR: Cannot open log file!"; while (<CHECKFILE>) { $check_list = <CHECKFILE>; if ($check_list =~ /get_check:'([^']*)'/) { $get_check = $1; close CHECKFILE; } } my $post_cmd = $wget_cmd . ' --no-proxy -O renrenlogin1.log --post-data="c=' . $text . '&raw=' . $text . '&isAtHome=0&publisher_form_ticket=' . $get_check .'" --keep-session-cookies --load-cookies=renrencookie http://status.renren.com/doing/update.do --referer=http://status.renren.com/ajaxproxy.htm'; system($post_cmd); open LOG, "> $logfile" || die "ERROR: Cannot open log file!"; print LOG $latest_text; close LOG; } if ($latest_text eq "") { print "Fucking dead!"; } }
没有评论