Skip to content

Instantly share code, notes, and snippets.

@joecannatti
Created March 27, 2012 03:41
Show Gist options
  • Save joecannatti/2212308 to your computer and use it in GitHub Desktop.
Save joecannatti/2212308 to your computer and use it in GitHub Desktop.
bike.pl
#!/usr/bin/env perl
use strict;
use warnings;
use LWP;
use Mojo::DOM;
my $browser = LWP::UserAgent->new;
my $url = "http://cleveland.craigslist.org/bik/";
my $response = $browser->get( $url );
my $html = $response->content;
my $already_reported_bikes="bikes";
open(DAT, $already_reported_bikes);
my @raw_data=<DAT>;
close(DAT);
my $dom = Mojo::DOM->new;
$dom->parse($html);
for my $a ($dom->find('p.row a')->each) {
my $title = $a->text;
if($title =~ m/(fixed|single|track|trak|fixie)/i){
my $href = $a->attrs->{href};
unless("$href\n" ~~ @raw_data){
open(DAT, ">>$already_reported_bikes");
print DAT "$href\n";
close(DAT);
system("echo $href | mail -s \"There's a new bike you might like on Craigslist\" joecannatti\@gmail.com");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment