#!/usr/bin/perl # js.pl - JobServe Reformatter # (c) James Powell - Jan 2001 use CGI qw/:standard/; use CGI::Cookie; use LWP; use strict; use URI::Escape; use CGI::Carp qw(fatalsToBrowser); use Time::localtime; my $query = new CGI; #my $query = new CGI(\*STDIN); # DEBUG # get cookies # {{{ my %cookies = fetch CGI::Cookie; no strict "refs"; my @cooks = @{$cookies{jobsearch1}->{value}}; my %ckhash = @cooks; my @jobids = @{$cookies{jobidbook}->{value}}; my %jobidhash = @jobids; use strict "refs"; # }}} if ($query->param('q')) { my $ua = new LWP::UserAgent; $ua->agent("AgentName/0.1 " . $ua->agent); # Create a request my $queryurl = sprintf('http://www.it.jobserve.com/jobserve/searchresults.asp?JobType=%s&d=%s&order=DateTime&page=%s&q=%s', ($query->param('JobType') || $query->param('jobtype')), $query->param('d'), $query->param('page'), # $query->param('q')); # DEBUG uri_escape($query->param('q'), "^A-Za-z")); # print $queryurl; # DEBUG my $req = new HTTP::Request GET => $queryurl; # Pass request to the user agent and get a response back my $res = $ua->request($req); # log it if ($query->param('page') < 2) { my $tm = localtime(time); if (-d '/users/jamespo/www/jobserve/') { open(LOG,">>/users/jamespo/www/jobserve/usage.txt") or die $!; printf(LOG "%02d:%02d:%02d-%04d/%02d/%02d\t%s\t%s\n", $tm->hour, $tm->min, $tm->sec, $tm->year+1900, $tm->mon+1, $tm->mday, $ENV{'REMOTE_ADDR'}, $query->param('q')); close(LOG); } } # Check the outcome of the response if ($res->is_success) { my $jsreply = $res->content; if (($query->param('page') == 1) && !$query->param('nw')) { # save query in cookie my $cookie = new CGI::Cookie(-name=>'jobsearch1', -value=>{ JobType => $query->param('JobType'), d => $query->param('d') }, -expires => '+30d' ); my $cookie2 = new CGI::Cookie(-name => 'q', -value => $query->param('q'), -expires => '+30d' ); print header(-cookie=>[$cookie, $cookie2]); } else { print header; } print &output_listing($jsreply); # print "Query: " . $query->param('JobType') . " Q:" . $query->param('q') . "
"; # DEBUG # print $queryurl; # DEBUG } else { &output_html('Request to jobserve failed'); } } elsif ($query->param('jobid')) { # details page print header, &detailspage($query->param('jobid')); } elsif ($query->param('jsform')) { # form page if ($query->param('jobidbook')) { # bookmark to add if ($query->param('jobidbook') == -1) { # if you get passed -1, wipe the bookmarks cookie %jobidhash = {}; } else { $jobidhash{$query->param('jobidbook')} = $query->param('jobtitle'); } my $cookie3 = new CGI::Cookie(-name=> 'jobidbook', -value=> \%jobidhash, # set negative exp. date if they have to be deleted -expires => keys(%jobidhash) ? '+30d' : '-30d' ); print header( -cookie => $cookie3), &jsform; } else { print header, &jsform; } } elsif ($query->param('blank')) { &output_html(''); } else { # frameset is default now print header, &frameset; } # {{{ openwindow sub openwindow { my $rettxt = shift; # any stuff that comes before $rettxt .= (!$query->param('nw')) ? sprintf('  New Window', self_url . '&nw=1') : ''; return $rettxt; } # }}} # {{{ output_html sub output_html { my $txt = shift; print header; print start_html(-title=>'Jobserve Reformatter Results', -bgcolor=>'white'), $txt, end_html; } # }}} # rewrite details page # {{{ detailspage sub detailspage { my $jobid = shift; my $ua = new LWP::UserAgent; $ua->agent("AgentName/0.1 " . $ua->agent); # Create a request my $queryurl = sprintf("http://www.it.jobserve.com/jobserve/JobDetail.asp?jobid=%s", $jobid); my $req = new HTTP::Request GET => $queryurl; # Pass request to the user agent and get a response back my $res = $ua->request($req); # Check the outcome of the response my $jsreply; if ($res->is_success) { $jsreply = $res->content; } # strip header & footer $jsreply =~ s#^.*]+>##si; $jsreply =~ s#.*##si; $jsreply =~ s|width='600'|width="100%"|sig; # change table widths # remove title shite # $jsreply =~ s#.*##; $jsreply=~ s###s; $jsreply =~ s|(
)|openwindow($1)|sei; # put "open in new window link" # hide eligibility $jsreply =~ s/For jobs.*applying.//gis; $jsreply =~ s/Eligibility//; $jsreply =~ s/border=1/border=0/; # fix links to agency $jsreply =~ s#[^']*JobDetailMailToClick.asp[^']*&url=([^']+)*#&fixlink('mailto:',$1)#eg; $jsreply =~ s#[^']*LinkClick.asp[^']*&url=([^']+)#&fixlink('',$1)#eg; sub fixlink { my ($pre, $tofix) = @_; return $pre . uri_unescape($tofix); } # $jsreply=~ s# #\n#g; # DEBUG # fix cellpadding $jsreply =~ s#cellpadding=3#cellpadding=1#g; $jsreply =~ s#cellpadding='0'#cellpadding=1#g; # add bookmark link after new window $jsreply =~ /jobid=(\d+)/; my $jobid = $1; $jsreply =~ m#([^>]+)#; (my $jobtitle = $1) =~ s/^(\w+\W\w+).*$/$1/; my $bookmark .= sprintf('     Bookmark', $jobid, uri_escape($jobtitle)); $jsreply =~ s#New Window#New Window$bookmark#; return $jsreply; } # }}} # {{{ output_listing sub output_listing { my $jsreply = shift; # strip header & footer $jsreply =~ s#^.*]+>##si; $jsreply =~ s#.*##si; $jsreply =~ s/]+>//sg; # remove stylesheet ref $jsreply =~ s#(searchresults|JobDetail)\.asp#http://www.it.jobserve.com/jobserve/$1.asp#g; # fix job links $jsreply =~ s#]*/images/(banners|sskills)/[^>]*>##sig; # strip banners $jsreply =~ s|||si; # whip the searchbox off as well $jsreply =~ s|size='?(\d)'?|&decit($1)|eg; # make font smaller $jsreply =~ s|class=[\b>]+||g; # remove class $jsreply =~ s|width='600'|width="100%"|sig; # change table widths # make detail pages open in correct frame $jsreply =~ s|('http://www.it.jobserve.com/jobserve/JobDetail.asp\?jobid=\w+')|$1 target="detail"|g; # make details pages go through crap stripper $jsreply =~ s|'http://www.it.jobserve.com/jobserve/JobDetail.asp\?jobid=(\w+)'|"js.pl?jobid=$1" target="detail"|g; # change other page links to go through stripper $jsreply =~ s|http://www.it.jobserve.com/jobserve/searchresults.asp\?([^"]+)|js.pl?$1|g; $jsreply =~ s|"/jobserve/bannerclick.asp[^"]+"|""|g; # strip banner crap $jsreply =~ s|(Matching Jobs\.)|openwindow($1)|ei; # put "open in new window link" # $jsreply=~ s# #\n#g; # DEBUG # decit - small sub to decrement font size if > 1 for regexp sub decit { return sprintf('size="%s"', ($_[0] > 1) ? $_[0]-1 : $_[0] ); } return $jsreply; } # }}} # {{{ jsform sub jsform { my $query = exists($cookies{q}) ? $cookies{q}->value : ''; my $duration; $duration = '\n"; my $jobtype; $jobtype = '\n"; my $bookmarks; $bookmarks = '
'; my $html=< Jobserve Reformatter Query Form
    $jobtype Within $duration Days
$bookmarks [Reset]
EOF return $html; } # }}} # {{{ frameset sub frameset { my $html=< Jobserve Reformatter

Jobserve Reformatter

You need a browser that supports frames, luddite, otherwise just go here
EOF return $html; } # }}}