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

9 comments:

Saurabh 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

Rashmi said...

Hi

There is going to be a Blogcamp in India on 16th of June. Around 250 bloggers will be taking part in the event.

This is what they say on their blog: "The way unconferences work is that, you don't have an agenda, rather we will put up a white board, where participants will themselves add the topics they are interested to speak upon. Depending upon the number of speakers we will go for multiple threads. There will be some intense discussions, we will have a lot of fun and yes there will be blogging, video blogging, photo blogging, podcasting ... everything under the blogger sun."

The registrations have started. We are planning to have 250 participants from all over the country. There are some people taking part virtually, using youtube, slideshare, skype etc. if you are interested please add your name to the wiki.

Check the:
wiki: http://barcamp.org/BlogCampPune
official blog: http://www.blogcamppune.blogspot.com

rashmi

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??

Carder International 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.....

Mayur Vaghasia said...

visit http://hacking26.blogspot.com/ for more info.

Dushyant Kotadia said...

For Windows Hack, Tips & Tricks visit

http://windows-tips44.blogspot.com/



.

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

Anonymous said...

تحضير البوراك بالبيض
تردد قناة كوريا تي في
تردد قناة كوريا تي في 2013
قناة كوريا تي
تردد قناة الفراعين - تردد قناة الفراعين 2012 - تردد قناة الفراعين الجديد
برنامج النكت للجوال
برنامج النكت للجوال 2013
لنكت للجوال 2013
لنكت للجوال
برنامج Nokat
أسماء بنات
أسماء بنات 2013
تحميل سكاي بي
ستائر 2013
ستائر
رمزيات بلاك بيري - رمزيات بلاك بيري 2013
صور بنات كول