Archive

Archive for the ‘Perl’ Category

Yahoo Finance Get Industry and Sector using Perl

May 20th, 2008

This script parses yahoo finance an pulls the Industry and sector for any ticker symbol you pass it. I used it to create a stock screener I am working on. Hope it becomes useful for you.


#!c:\perl\bin\perl.exe
use LWP::Simple;
use LWP::UserAgent;
use HTML::TableExtract;

if ($#ARGV != 0) {
print “$#ARGV usage: need to pass in a symbol\n”;
exit;
}
$sym = $ARGV[0];

my $url = “http://finance.yahoo.com/q/in?s=$sym”;
my $capture = get($url);

$te = HTML::TableExtract->new( depth => 2, count => 0 );
#print “$depth,$i\n”;
$te->parse($capture);
my $table = $te->first_table_found;
foreach $ts ($te->tables) {
#print “Table found at “, join(’,', $ts->coords), “:\n”;
foreach $row ($ts->rows)
{
$a = @$row->[0];
$b = @$row->[1];
print “$a $b\n”;
}
}

Greg Finance, Perl

FLEX and Perl Export to Excel

May 1st, 2008

Need to export a Flex Datagrid to Excel CSV?

Here is a link to the Flex code

The flex code will convert the DataGrid to a CSV string. Which you will then post to a cgi….code below.

You can see it in action on my Dividend Reinvestment Tool 

#!/usr/bin/perl
use CGI qw(:standard);
my $cgi = new CGI;
my $count = 0;
use CGI::Carp qw(fatalsToBrowser);
$title=$cgi->param('title');
$html=$cgi->param('htmltable');
$type = $cgi->param('type');
if ($type = "CSV") {
print $cgi->header(-expires=>'now', -type=>'application/x-csv', -content_disposition=>"attachment; filename=$title.csv");
print "$html";
}
else {
print $cgi->header(-expires=>'now', -type=>'application/octet_stream', -content_disposition=>"attachment; filename=$title.xls");
print $cgi->start_html(-title => 'Export'
);
print "$html";
print $cgi->end_html;

Greg FLEX, How-To, Perl