Skip to content

Instantly share code, notes, and snippets.

@shalk
Created June 18, 2015 08:43
Show Gist options
  • Save shalk/26f16d06c1191478a513 to your computer and use it in GitHub Desktop.
Save shalk/26f16d06c1191478a513 to your computer and use it in GitHub Desktop.
stock info
sub stockinfo1{
# 使用腾讯的接口
my $stockid = shift;
my $url1="http://qt.gtimg.cn/q=$stockid";
my $ua = Mojo::UserAgent->new();
my $res = $ua->get($url1)->res->body;
$res = encode("utf8",decode("gbk",$res));
(
undef,
my $name, #名称
my $code, #代码
#3-5
my $current_price, #当前价格
my $yesterday_price, #昨日收盘
my $today_open_price, #今日开盘
#6-8
my $totalNumber, #成交量
my $outNumber, #外盘
my $innerNumber, #内盘
#9~18
my $buy1,
my $buyPrice1,
my $buy2,
my $buyPrice2,
my $buy3,
my $buyPrice3,
my $buy4,
my $buyPrice4,
my $buy5,
my $buyPrice5,
#19~28
my $sell1,
my $sellPrice1,
my $sell2,
my $sellPrice2,
my $sell3,
my $sellPrice3,
my $sell4,
my $sellPrice4,
my $sell5,
my $sellPrice5,
undef,
my $CurrentTime,
my $UpdownPrice,
my $UpdownPercent,
my $HighPrice,
my $LowPrice,
undef,
undef,
my $totalMony,
my $changePercent,
my $shiYing,
undef,
undef,
undef,
my $zhenFu,
) = split /~/,$res;
my $reply;
$reply .= "股票名称: $name($code)\n";
$reply .= "------------------------\n";
$reply .= "当前价格:$current_price\t\t" ,"开盘价格:$today_open_price\n";
$reply .= "昨日收盘:$yesterday_price\n";
$reply .= sprintf "幅度 :%-15s换手率 :%-17s\n",$UpdownPercent."%",$changePercent."%";
$reply .= "成交量 :$totalNumber\n";
$reply .= "------------------------\n";
$reply .= sprintf "买一 :%-8s %-5s卖一 :%-8s %-5s\n",$buy1,$buyPrice1,$sell1,$sellPrice1;
$reply .= sprintf "买二 :%-8s %-5s卖二 :%-8s %-5s\n",$buy2,$buyPrice2,$sell2,$sellPrice2;
$reply .= sprintf "买三 :%-8s %-5s卖三 :%-8s %-5s\n",$buy3,$buyPrice3,$sell3,$sellPrice3;
$reply .= sprintf "买四 :%-8s %-5s卖四 :%-8s %-5s\n",$buy4,$buyPrice4,$sell4,$sellPrice4;
$reply .= sprintf "买五 :%-8s %-5s卖五 :%-8s %-5s\n",$buy5,$buyPrice5,$sell5,$sellPrice5;
return $reply;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment