免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: xti9er
打印 上一主题 下一主题

我的股票机 [复制链接]

论坛徽章:
0
31 [报告]
发表于 2009-06-05 09:39 |只看该作者

修改了个支持代理的版本

#!/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分享!!!

论坛徽章:
0
32 [报告]
发表于 2009-06-05 09:42 |只看该作者

回复 #1 xti9er 的帖子

太牛了,我这个新手什么时候才能做出这种效果呢

论坛徽章:
0
33 [报告]
发表于 2009-06-05 10:26 |只看该作者
学习

论坛徽章:
0
34 [报告]
发表于 2009-06-06 11:02 |只看该作者
GOOD!

论坛徽章:
0
35 [报告]
发表于 2009-06-06 11:59 |只看该作者
不错!

论坛徽章:
0
36 [报告]
发表于 2009-08-11 23:52 |只看该作者
bucuo a               ..................

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
37 [报告]
发表于 2009-08-12 12:30 |只看该作者
好!

论坛徽章:
0
38 [报告]
发表于 2009-08-17 13:35 |只看该作者
Insecure $ENV{PATH} while running with -T switch at E:/workspace/PerlTest/testTK.pl line 6.

这是什么意思?环境变量?

只要把system("cls");这句去掉就不报错了.

怎么解决下呢?

论坛徽章:
0
39 [报告]
发表于 2009-08-26 12:52 |只看该作者
牛就一个字

论坛徽章:
0
40 [报告]
发表于 2009-09-15 12:56 |只看该作者
很强大~~~
看到了color:utpur,一直再找的好东西
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP