#!/usr/bin/perl
# cfb 1.0.1 03jul2006
# executed automatically by ./bloombergBBMX, in turn exec by 
# /etc/daily.local
# massage Bloomberg MassIndex 
# 1.0.1: updated for new Bloomberg URL, website design a/o 27jun2006

print "\nBloombergMAIndex v1.0.1\n\n";
print "C F Baum  Jul 2006\n\n";
use LWP::Simple;
use Text::Wrap;
$dir = "MassInd";
$tick = "BBMX";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$yy = $year+1900;
$mon++;
$quote = $yy.$mon.$mday;
#$ouf=">/volumes/loki1/fmwww/repec/RAIM/".$dir."/bloomberg_".$tick."_".$quote."ind.raw";
$ouf=">/fmwww0/repec/RAIM/".$dir."/bloomberg_".$tick."_".$quote."ind.raw";

#$ouf=">bloomberg_".$tick."_".$quote."ind.raw";

open(OUT,$ouf) || die "Cannot open $ouf for output";

$ymd = $yy."-".$mon."-".$mday;
print "$ymd\n";
#$str = get("http://www.bloomberg.com/markets/stocks/regional_indices.html");
$str = get("http://www.bloomberg.com/apps/quote?ticker=bbmx:IND");
$str =~ s/\n/ /igm;
($date) = ($str =~ /Heading">(.+?)\&/ig);

(@chunk) = ($str =~ /"QuoteTableData(.+?)</ig);

#($mass) = ($str =~ /MASSACHUSETTS(.+?)<tr>/m);
#(@chunk) = ($mass =~ /<span.+?>(.+?)</ig);
#$chunk = @chunk;
$i=0;
foreach(@chunk) {
	$i++;
	if ($i<4) {
		$temp = $_;
		$temp =~ s/">//ig;
		$temp =~ s/Up//ig;
		print OUT "$temp \t";
		}
		
	}
print OUT "$date\t$yy\n";
__END__

