Get Band Tour Info

#!/usr/bin/perl
# 
# Get upcoming band tour info.
# Find new band info at http://www.tourtracker.com/
#
# Example contents of input file, bands.txt
#  all-shall-perish/2233318/
#  death-angel/1003433/
#  three-inches-of-blood/1516753/
#  havok/1268698/
#

use LWP::Simple;
use HTML::TreeBuilder;

@today = localtime(); #get date variables
$now = sprintf('%02u%02u%02u',$today[5]+1900,$today[4]+1,$today[3]); 

$tourtracker = 'http://www.tourtracker.com/artist/'; # Base url for tour dates

open(OUT, "> $now.html") || die $!; # Output file name DATE.html
open(BANDS, "< bands.txt") || die $!; # Format for file tour-tracker-band-name/band-id/ 

$user_agent = LWP::UserAgent->new();

while (<BANDS>)
	{
	$page = HTML::TreeBuilder->new();
	chomp;
	$request = HTTP::Request->new(GET => "$tourtracker$_"); #for each entry in BANDS get the entire web page
	$response = $user_agent->request($request);
	$content = $response->content;
	$page->parse($content);
	$search_results= $page->look_down(sub{ $_[0]-> tag() eq 'table' and ($_[0]->attr('class') =~ /upcoming/)}); # Parse the content for the table containing Upcoming Shows.
	print OUT "<H1>$_</H1>\n"; # Print an html header with the band name
	if ($search_results != NULL){
		print OUT $search_results->as_HTML; #If there are Upcoming Shows print them.
		}
		else{
		print OUT "No Current Tour Dates\n"; #Else print this
		}
	$page->delete;
}

Leave a Reply

Your email address will not be published. Required fields are marked *