- 论坛徽章:
- 0
|
#!/user/bin/perl -w
#By xti9er www.xtiger.net
use LWP::Simple;
use Color::Output;
Color::Output::Init;
$|=1;
my $fst=0;
my $stimeout;
my $googleq="";
my $nowsc=0;
my (@scode,@sc,@spr);
START:
system("cls");
`title --= M y S t o c k S c r e e n e r =--`;
cprin("\tM y S t o c k S c r e e n e r\n\n",7);
cprin("_"x60,13);
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=~/^#/;
my ($scode,$sc,$spr)=split(/=/,$info);
push(@scode,$scode);
push(@sc,$sc);
push(@spr,$spr);
}
$allst=scalar(@scode);
$fst=1;
for(@scode)
{
if(my $nowcode=getcode($_))
{
$googleq=$googleq."id-$nowcode,";
print ".";
}
else{next;}
}
#print "$googleq\n";
goto START;
}
sub getcode
{
my $newst=shift;
my $nowcode=get("http://www.google.cn/finance?q=$newst");
if($nowcode=~/<span\sclass=\"pr\"\sid=\"ref_(\d+)_l\"\>/)
{
return $1;
}
else
{
return 0;
}
}
print "\n当前时间:".scalar(localtime())."\n";
cprin("_"x60,13);
if(my $googled=get("http://www.google.cn/finance/info?q=$googleq&infotype=infoquoteall&hl=zh-CN&gl=cn"))
{
my @info=split(/\,/,$googled);
print "\n股票码\t开盘价\t成本价\t持有量\t",$stimeout=0?"当前价\t":"收盘价\t","涨跌\t盈亏\t名称\n";
for my $newinfo(@info)
{
#print "$newinfo\n";
$nowsc=0 if $nowsc>$allst-1;
if ($newinfo=~/\"(.*)\"\s\:\s\"(.*)\"/)
{
my $infot=$1;
my $infoc=$2;
next if $infot=~/avvo|ccol|l_cur|lt|fwpe|beta|lo52|hi52/;
#print "$infot=$infoc\n";
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 "cp"){$cp=$infoc}
if($infot eq "lname"){$lname=$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);
print "$spr[$nowsc]\t";
print "$sc[$nowsc]\t";
cprin("$l\t",($l-$op)>0?5:7);
cprin("$cp\t",$cp>0?5:7);
my $gl=int($sc[$nowsc] * ($l-$spr[$nowsc]));
cprin("$gl\t",$gl>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);} |
##############################
新增加功能:
1、配置文件st.ini
内容格式如下:
##########################
#股票代码=成本价=持有量
600000=****=39.513
600022=****=4.169
600690=****=10.186
##########################
2、根据配置文件中的关注股票和持有信息,计算当前盈利状况
上次发的代码,很多朋友提了不少建议。有些呢实现起来不现实,比如K线图,那是需要长期的数据作为支持的。
还有些功能,也懒得写,因为我不需要。说实话,没多少时间搞这些没什么产出的东西。大家如果觉得合适用呢,可以拿去用。我不会再改了。
[ 本帖最后由 xti9er 于 2009-5-17 23:07 编辑 ] |
|