#!/usr/bin/perl # gas_price.pl is Copyright 2005 by James 'J.C.' Jones # Email: jcjones AT ufl DOT edu # Site: http://pug.ibu02.com/ # # This program makes use of the website at floridastategasprices.com # and the user of this script is subject to that site's terms of service. # # This file's web home is at http://www.cise.ufl.edu/~jcjones/src/ . # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $links = `which lynx 2>&1`; $links = `which links 2>&1` unless ($links =~ /^\//); $links = `which elinks 2>&1` unless ($links =~ /^\//); chomp $links; $curl = `which curl 2>&1`; chomp $curl; $wget = `which wget 2>&1`; chomp $wget; if ($curl =~ /^\//) { $cmd = "${curl} -s"; } elsif ($wget =~ /^\//) { $cmd = "${wget} -q -O -"; } elsif ($links =~ /^\//) { $cmd = "${links} -source"; } else { die "You don't have curl, links, elinks, lynx, or wget. You need at least one of those programs."; } $whered = join '%20', @ARGV; $where = join ' ', @ARGV; die "Where do you want to check the gas prices? use Florida city name as argument.\n" unless ($where =~ /.../); get_price($where); exit; sub trimwhitespace($) { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; } sub get_price { @where = @_; for my $where (@where) { print "Prices for area $where.. (using ${cmd})\n"; print " \$\tStation\t\tTime Recorded\tAddress\n"; print " --------------------------------------------------------\n"; open PRICE, "${cmd} 'http://www.floridastategasprices.com/index.aspx?s=Y&fuel=A&area=${whered}&tme_limit=72' |"; while() { if (/PColLow.*\>(\d\.\d\d)\; $place=; $b=; $b=;$b=; $b=;$b=; if ($b =~ /PList.*\>(.*)\<.*\>(\d{1,2}:\d\d [AP]M)\;$b=;$b=;$b=;$b=; if ($b =~ /PAddress.*\>(.*)\