#!/usr/bin/perl -w
use strict;
use CGI;
# get joblinks
# Check for recent jobs in 5 categories and return links
# check for a few start and end dates
# category anchors, to avoid icky month transformations
my $query = CGI->new();
my @begindate = split (/ /, scalar localtime);
my ($Q,$dow,$mon,$day,$hh_mm_ss,$tz,$yyyy) = @begindate;
my $endday = ($day - 6);
my $base = 'http://www.craigslist.org';
my @categories = qw/eng sad tch art bus nby\/apa nby\/roo/;
print $query->header( "text/html" ),
$query->start_html(-title => "CraigsList Distillate",
-bgcolor => "#ffffaa" ),
$query->h1( "GetJobs.pl" );
print "";
foreach (@categories) {
print "$_ ";
}
for my $i (0 .. $#categories) {
open HANDLE_IN, "lynx -source http://www.craigslist.org/sfo/$categories[$i] |" or die "can't open HANDLE_IN $!";
my $grab = 0;
while () {
my $newdate = &newdate($_);
next unless(($newdate) && (/bgcolor/)) || ($grab ne 0);
print "
$categories[$i]
Top " if $grab == 0;
s|href=\/|href=$base\/|ig;
$grab++;
my $olddate = &olddate($_);
print unless $olddate;
last if $olddate;
}
close HANDLE_IN;
}
print $query->end_html;
sub olddate { #is the date more than a few days old?
return () unless /\s([\w]{3}\s[\d]+)[\w]{2}/;
my ($mon, $dd) = split (/ /, $1);
my $test = $dd - $endday;
$test <= 0 ? (1) : ();
}
sub newdate { #is the date less than a few days old?
return () unless /([\w]{3}\s[\d]+)/;
my ($mon, $qd) = split (/ /, $1);
my $test = $qd - $endday;
$test >= 0 ? (1) : ();
}