# Get the best known unleaded gas price for each zip code in a list, and one seller.
# Version 0.0.3
#Enhancements done:
#Enhancements underway:
#Enhancements proposed:
# o Save all places with the best zip code, not just the best; report them.
# o Log each gas price, etc. encountered in a .CSV file, for later analysis
use Gas::Prices2;
my @zip_Chi = ("60609", "60601", "60622");# Testing. Zip in the Chicago area.
my @zip_I44 = ("63025", "63039", "63069", "63079", "65441", "65453", "65559", "65560",
"63128", "63129", "65401", "65479", "65559", "65571",
); # I-44 corridor. Not a zip code? "65501",
my @zip_SLm = (
"63021", # Ballwin
"63032", "63033", "63034", # Florissant
"63101", "63108", # (downtown)
"63111", # (South City)
"63130", # (U City)
"63141", "63146", # (Creve Coeur)
"63301", "63302", "63303", "63304", # (St. Charles)
"63376", # (St. Peters)
); # St. Louis metro area, not near home/work/commute
my @zip = ("63031",
"63043", "63074", # (work-work commute: Maryland Heights, St. Ann)
"63121", # (work: Normandy)
"63042", # (work commute route: Hazelwood)
"63134", # (work commute route? Berkeley?)
); # St. Louis metro (parts close to home/work/commute)
# my @zip = @zip_Chi; ## Test w/ stations in some Chicago zip codes
# my @zip = @zip_SLm; ## Test w/ zip codes elsewhere in StL metro area
# my @zip = @zip_I44; ## Run w/ stations along the I-44 corridor betw StL and Rolla
# my @zip = ("63302");## one-shot value
if (0) {
my %tmp = ();
foreach (@zip, @zip_Chi, @zip_I44, @zip_SLm) {
$tmp{$_} = 1;
};
@zip = keys(%tmp);
};
my %PicToPrice = (
); # Entries not found in the module but should be -- normally none
my %NoPrice = ();
my %results = ();
# Enhancements/fixes
# Done:
# Doing:
# To do:
# Use a hash to accumulate references to (unique) gas stations; key is address
# When printing, put the zip code before the station name name, remove it from the end of the address
# Group results by zipcode (forget about by price)
# Group results by price (forget about by zipcode)
foreach (@zip) {
my $zip =$_; # Move $zip into "for" stmt in line above
my $gp = new Gas::Prices2($zip);
if (defined($gp)) {
my @gas_stations = @{$gp->get_stations};
foreach(@gas_stations) # This loop prints debug info
{
print "Station name:" . $_ -> {station_name} . "\n" .
"Station address:" . $_ -> {station_address} . "\n" .
"Unleaded price:" . $_ -> {unleaded_price} . "\n" .
"Unleaded date:" . $_ -> {unleaded_date} . "\n" .
"Plus price:" . $_ -> {plus_price} . "\n" .
"Plus date:" . $_ -> {plus_date} . "\n" .
"Premium price:" . $_ -> {premium_price} . "\n" .
"Premium_date:" . $_ -> {premium_date} . "\n" .
"Diesel price:" . $_ -> {diesel_price} . "\n" .
"Diesel date:" . $_ -> {diesel_date} . "\n"
if (0); #Don't really want to print it
}
my $cheapest_unleaded = $gp->get_cheapest_station("unleaded");
# print "Start of HTML_table_row:", substr($cheapest_unleaded->{HTML_table_row}, 0, 40), ":\n";####
# print "<!-- --> "; #### beg New 2008/05/01
# my $HTML_table_row = $cheapest_unleaded->{HTML_table_row};
# $cheapest_unleaded->{HTML_table_row} = ""; ## delete is better than shorten, but ...
# for (my $i = 0; $i<length($HTML_table_row); $i++) {
# print substr($HTML_table_row, $i, 50);
# };
# my @HTML_table_row = split "<span", $HTML_table_row;
# print "\n"; #### end New 2008/05/01
if ($cheapest_unleaded->{unleaded_price} == "unkwn") {
my $price = $PicToPrice{$cheapest_unleaded->{unleaded_price_pic}};
if ($price) {
$cheapest_unleaded->{unleaded_price} = $price;
$NoPrice{$cheapest_unleaded->{unleaded_price}} = "Put this price in module: ".$price, " for this key ".
$cheapest_unleaded->{unleaded_price_pic};
# print "Hey! I found a look-up price (", $cheapest_unleaded->{unleaded_price}, ") for zip ", $zip, "\n";####
} else {
$NoPrice{$cheapest_unleaded->{unleaded_price_pic}} = $cheapest_unleaded->{station_address};
# print "Ho hum! I failed to look up a price (", $cheapest_unleaded->{unleaded_price_pic}, ") for zip ", $zip, "\n";####
};
} else {
# print "Hey! It returned a price (", $cheapest_unleaded->{unleaded_price}, ") for zip ", $zip, "\n";####
};
#### print "<!-- --> <tr><form>Enter/correct/verify the price ", # Does not build something that reliably displays the cached image
#### $cheapest_unleaded->{unleaded_price}, " </form>",
#### "<span>",
#### substr($cheapest_unleaded->{unleaded_price_pic},0,10),
#### "
http://autos.msn.com",
#### substr($cheapest_unleaded->{unleaded_price_pic},10),
#### "</span></tr><br>\n";
$results{$cheapest_unleaded->{station_address}} = $cheapest_unleaded;
};
if (0) {
print $zip . " \$" .
$cheapest_unleaded->{unleaded_price} .
" unleaded " .
$cheapest_unleaded->{station_name} . " at " .
$cheapest_unleaded->{addr_nozip} . "\n";
};
};
foreach (sort keys %results) {
my $cheapest_unleaded = $results{$_};
my @addrparts = split / /,$cheapest_unleaded->{station_address};
my $zip = pop @addrparts;
print $cheapest_unleaded->{unleaded_price} .
" unleaded " .
$zip . " " .
$cheapest_unleaded->{station_name} . " at " .
(join " ", @addrparts) . "\n";
};
foreach (sort keys %NoPrice) {
#### print "\t\t\t\t\t\t #'", $_,"' => \"\", # ", $NoPrice{$_},"(GasPrices_Demo.pl)\n";
};