- 论坛徽章:
- 0
|
修改了个支持代理的版本
#!/usr/bin/perl -w
#By xti9er www.xtiger.net
use LWP::Simple;
use LWP::UserAgent;
use Color::Output;
Color::Output::Init;
$|=1;
my $fst=0;
my $stimeout;
my $googleq="";
my $nowsc=0;
#my (@scode,@sc,@spr);
#my (@scode,@sc,@spr);
#$scode="0";
my %sc=("","");
my %spr=("","");
system("clear");
#`title --= M y S t o c k S c r e e n e r =--`;
my $ua = LWP::UserAgent->new;
#$ua->proxy('http', 'http://172.21.148.5:25880');
#$ua->max_size( 8192 );
$ua->env_proxy;
if($fst==0)
{
cprin("\n程序开始初始化",13);
my @gettime=localtime();
if($gettime[2]>15 or $gettime[2]<9){$stimeout=1}
else{$stimeout=0}
open(ST,"st.ini") or die $!;
while(my $info=<ST>)
{
chomp($info);
next if $info=~/^#/;
($scode_t,$spr_t,$sc_t)=split(/=/,$info);
if ($scode_t eq "" or $spr_t eq "" or $sc_t eq "") {die "\n请正确填写需要查看的股票在st.ini中,格式 股票代码=持有价格=持有量\n"}
$sc{$scode_t}=$sc_t;
$spr{$scode_t}=$spr_t;
$googleq=$scode_t.",$googleq";
#print "$googleq\n";
}
$allst=scalar(@scode);
$fst=1;
if($googleq eq "") {die "\n请正确填写需要查看的股票在st.ini中,格式 股票代码=持有价格=持有量\n"}
#for(@scode)
#{
# if(my $nowcode=getcode($_))
# {
# $googleq=$googleq."id-$nowcode,";
# print ".";
# }
# else{next;}
#}
#print "$googleq\n";
}
sub getcode
{
my $newst=shift;
my $nowcode=$ua->get("http://www.google.cn/finance?q=$newst");
$nowcode=$nowcode->as_string;
if($nowcode=~/<span\sclass=\"pr\"\sid=\"ref_(\d+)_l\"\>/)
{
return $1;
}
else
{
return 0;
}
}
START:
my $googled;
if($googled=$ua->get("http://www.google.cn/finance/info?q=$googleq&infotype=infoquoteall&hl=zh-CN&gl=cn") and $googled->is_success)
{
system("clear");
cprin("\tM y S t o c k S c r e e n e r\n\n",7);
cprin("_"x60,13);
print "\n当前时间:".scalar(localtime())."\n";
print "\n股票码\t开盘价\t成本价\t持有量\t",$stimeout=0?"当前价\t":"收盘价\t","涨跌\t盈亏\t名称\n";
my @info=split(/\,/,$googled->as_string);
#my @info=split(/\}\s,\{/,$for_tt);
for my $newinfo(@info)
{
#print "$newinfo\n";
#$nowsc=0 if $nowsc>$allst-1;
my @info1=split(/,/,$newinfo);
for my $newinfo1(@info1)
{
if ($newinfo1=~/\"(.*)\"\s*\:\s*\"(.*)\"/)
{
#print "$newinfo+++\n";
my $infot=$1;
my $infoc=$2;
#print "1==$infot,2==$infoc\n";
next if $infot=~/avvo|ccol|l_cur|lt|fwpe|beta|lo52|hi52/;
if($infot eq "t"){$t=$infoc}
if($infot eq "op"){$op=$infoc}
#if($infot eq "hi"){$hi=$infoc}
#if($infot eq "lo"){$lo=$infoc}
if($infot eq "l"){$l=$infoc}
if($infot eq "c"){$c=$infoc}
if($infot eq "cp"){$cp=$infoc}
if($infot eq "lname"){$lname=$infoc}
if($infot eq "id"){$cursc=$infoc}
if ($infot eq "type")
{
print "$t\t";
print "$op\t";
#cprin("$hi\t",($hi-$op)>0?5:7);
#cprin("$lo\t",($lo-$op)>0?5:7);
#cprin("$l\t",($l-$op)>0?5:7);
#my $gl=int($sc[$nowsc] * ($l-$spr[$nowsc]));
#cprin("$gl\t",$gl>0?5:7);
print("$spr{$t}\t");
print("$sc{$t}\t");
print("$l\t");
cprin("$c\t",$c>0?5:7);
cprin(($l-$spr{$t})*$sc{$t}-($l*$sc{$t}/1000)."\t",($l-$spr{$t})*$sc{$t}-($l*$sc{$t}/1000)>0?5:7);
print "$lname\n";
print "-----------\n";
$nowsc++;
}
}
}
}
}
else
{
cprin("\n[!] GetInfo Fail\n",5);
}
sleep 10;
goto START;
sub cprin
{
($str,$i)=@_;
cprint("\x03" . $i . " $str\x030 |
支持代理的版本,使用HTTP_PROXY、FTP_PROXY等环境变量,HTTP代理测试可用,其他待测试。
需要的perl包:Color-Output-1.05.tar.gz , libwww-perl-5.826.tar.gz , URI-1.38.tar.gz
谢谢LZ分享!!! |
|