#!/usr/local/bin/perl -w # # MySpaceMusic v1e (c) 2008 Martin Hassel, code(cat)lacasahassel(dog)net # cat is at and dog is dot ;-) # # Developed with help and encouragement from Barbara Lublinn # # This program takes a list of artists/bands, together with the url to their # MySpace page, and checks them all against a list of towns/cities. # If a given city is found in a bands schedule the date, time and place is # extracted and presented. # # This program is free software; you can redistribute it and/or modify it under # the terms of either the Artistic License (which comes with Perl 5) or 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. # # A full copy of the GNU General Public License can be retrieved from # http://www.gnu.org/copyleft/gpl.html use LWP; $browser = LWP::UserAgent->new; use POSIX; %month = ( jan => 0, feb => 1, mar => 2, apr => 3, may => 4, jun => 5, jul => 6, aug => 7, sep => 8, oct => 9, nov => 10, dec => 11 ); # Load the list of bands to look for: myspacemusicbands.txt print "Reading: myspacemusicbands.txt\n"; open(BANDS, 'myspacemusicbands.txt') or die $!; @bands = ; close(BANDS); # Load the list of cities to look for: myspacemusiccities.txt print "Reading: myspacemusiccities.txt\n"; open(CITIES, 'myspacemusiccities.txt') or die $!; @cities = ; close(CITIES); $retries = 1; $maxretries = 100; print "Processing band list...\n"; foreach $band (@bands) { @band = split(/\t/,$band); $band = $band[0]; $url = $band[1]; $response = $browser->get($url); while((!$response->is_success || $response->content_type ne 'text/html') && $retries<$maxretries) { $response = $browser->get($url); print "Retry: ".($retries++)." ($band)\n"; sleep $retries; } if($retries>=$maxretries) { die "Can't get $url -- ", $response->status_line; die "Expected HTML; found ", $response->content_type unless $response->content_type eq 'text/html'; } $retries = 1; $content = $response->content; $content =~ s/^.*?
(.*?)<\/div>.*$/$1/gsi; @schedule = split(/<\/tr>\s*?/i,$content); foreach $city (@cities) { chomp $city; foreach $scheduleitem (@schedule) { $scheduleitem = fixsechars($scheduleitem); if($scheduleitem =~ m/$city/i) { $scheduleitem =~ m/(.*?)(.*?)(.*?)(.*?) time) { print "$band:\t"; print "$date\t$time\t$place\t$town\n"; } } } } } sleep 3; } sub fixsechars { $string = shift; $string =~ s/Ã¥/å/gsi; $string =~ s/ä/ä/gsi; $string =~ s/ö/ö/gsi; $string =~ s/Ã…/Å/gsi; $string =~ s/Ö/Ö/gsi; return $string; }