Friday, May 11, 2007

[Perl] Script to check stock

Script to check the stock and their graph :D
Uses finance.yahoo.com to get the graphs.

INPUT : stock.conf : contains stock symbol (one per line ) for each company.
You can find the symbols on http://finance.yahoo.com/lookup, if you don't know.

OUTPUT: Generates a html page that contains the information and graph for the given companies in stock.conf.

Requires: lynx
Usages: Put stocks.cgi and stock.conf in your cgi-bin directory. Open in firefox. Refresh to get latest info.
Note: you can also run the script from shell prompt and then redirect the output to a html file , then open this file in firefox :D But you need to run it every time you want the latest info.
# perl stock.cgi > mystocks.html
# firefox mystocks.html

Here are the files:

----- stocks.cgi ---
#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);
#Written by Vaibhav Gupta
################ Variables ######################
my $stockfile = "stock.conf";
my $tab_width = 3;
################################################

sub generatestockhtml () {
my @allfile = `cat $stockfile `;
my $toprint = "<table frame=box><tr>\n";
my $count=0;

foreach my $line (@allfile) {
chomp $line;
my ($firstchar) = ($line =~ /(.)/ );
my $stock=`lynx -source " http://finance.yahoo.com/d/quotes.csv?s=$line&amp;f=l1d1t1c6ohgn&e=.csv"` ;
my ($lasttrade,$lasttradedate,$lasttradetime,$change,$open,$dayhigh,$daylow,$name) = split(/,/,$stock);
#Not Printing lasttradetime
$toprint .="<td>
<b>$name</b> Trade Date = $lasttradedate <br>
Current: <font color=green>$lasttrade</font> Change:<font color=red> $change</font> <br>
Open: <font color=green>$open</font> High: <font color=green>$dayhigh</font> Low: <font color=green>$daylow</font>
<a href=\" http://ichart.yahoo.com/v?s=$line\">
<img src=\"http://chart.yahoo.com/c/0b/$firstchar/$line.gif\">
</a> <br>
<a href=\"http://finance.yahoo.com/q?s=$line&d=b\"> More Info</a>
</td>
\n";
$count++;
if($count % $tab_width == 0) {
$toprint .= "</tr><tr>";
}
}
$toprint .= "</tr></table>";
print $toprint;
}


print header("text/html"),
start_html("Vaibhav Gupta's Stock Page");
my $cur = CGI->new() ;
&generatestockhtml();
print end_html;

--- stock.conf --
goog
yhoo
msft
amzn
emc

7 comments:

Saurabh Joshi said...

Hi Vaibhav,
It would be also useful if you specify input/output pattern/example. Also, specify the dependencies (e.g. in this case "lynx" )

Rgds,
saurabh

Anonymous said...

Hey I wanted to download stock data from finance.yahoo.com and was using finance::quoteoptions module but I am nt able to retrieve anything..

Is it because of the proxy server we have in IITB??

Anonymous said...

I found useful tutorial blog that contains many software, tools, scripts to hack e-gold, paypal, ATM, credit cards and thousands valid credit card accounts as well as Paypal. This blog also sell many softwares that might be useful for hackers and carders. Check this blog:
http://www.hacking-egold.co.cc/

Chaoooo.....

Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!

Palm Pixi Plus Verizon Only Cell Phone with WebOS, Touch Screen said...

good article

Useful Talk said...

I have tested a few and the best hackers for hire on the dark web are the guys at dark web hackers, download Torbrowser and then go to this dark
web site with Torbrowser:
http://ziagmjbpt47drkrk.onion/

Dark Reviews said...


Hello
I have got a legit cc vendor in youtube. I think a lot of people like me is getting scammed every time thats why I'm sharing my knowledge to increasing awareness.
░▒▓█►👌 Best Darkweb reviews for Carding with legit site 👌◄█▓▒░
░▒▓█►👌 https://youtu.be/8sJ-RhgfoGY 👌◄█▓▒░
░▒▓█►👌 Best Darkweb reviews for Carding with legit site 👌◄█▓▒░
░▒▓█►👌 https://youtu.be/8sJ-RhgfoGY 👌◄█▓▒░
░▒▓█►👌 Best Darkweb reviews for Carding with legit site 👌◄█▓▒░
░▒▓█►👌 https://youtu.be/8sJ-RhgfoGY 👌◄█▓▒░