use LWP::UserAgent;

sub find {
	$url = 'http://www.bart.gov/scripts/aspx/fare_calc_ajax.aspx?orig='.
					$_[0].
					'&dest='.
					$_[1].
					'&trip=one-way';
	my $ua = LWP::UserAgent->new;$ua->agent("MyApp/0.1 ");
	my $req = HTTP::Request->new(GET=>$url);
	my $res = $ua->request($req);
	my $c = $res->content;
	#$c = '<strong>$1.75 / $0.65*</strong><p>One-way from<br><a href="/stations/ORIN">Orinda</a><br>to <a href="/stations/ROCK">Rockridge</a></p><p class="bot0">*Senior, Youth and RTC Clipper fare. Restrictions apply. <a href="/tickets/index.aspx" class="more-details">Read more</a></p>';
	$c =~ /\<strong\>\$([0-9]*\.[0-9]*)/;
	return $1;
}

open(F, "list.txt");
@l = <F>;
close(F);

open(G, ">fetched_fares.txt");

$ct = 0;

foreach $x (@l) {
	foreach $y (@l) {
		chomp($x);
		chomp($y);
		if(!($x eq $y)) {
			$t =  find($x, $y);
			$bar = $x . " " . $y . " " . $t . " "; 
			$baz = $bar ."\n";
			print $bar;
			print G $baz;
			if($ct%15 == 14) { print "\n"; }
			$ct++;
		}
		sleep(1);
	}
}

close G;
