#!/usr/bin/perl use CGI::Request; use Digest::MD5; #use Chart::Graph; #use Time::Local; $Chart::Graph::gnuplot = '/usr/local/bin/gnuplot'; $Chart::Graph::ppmtogif = '/usr/local/bin/ppmtogif'; # parse cgi $req = GetRequest(); # see if we're a new vistor if ($req->param('yourmom') ne "1") { makewebpage("cache/default.gif"); exit; } # see if we've cached this request $filename = "cache/" . generate_md5($req) . ".gif"; if (-f $filename) { makewebpage($filename); } else { generate_graph($filename); makewebpage($filename); } exit; sub generate_md5 { my ($req) = @_; my $ctx = Digest::MD5->new; $x = $req->as_string; @y = split /\<\/PRE\>/, $x; $ctx->add($y[0]); return $ctx->hexdigest; } sub makewebpage { my ($filename) = @_; $fm = $req->param('from_month'); $fy = $req->param('from_year'); $tm = $req->param('to_month'); $ty = $req->param('to_year'); $fms{$fm} = "selected"; $fys{$fy} = "selected"; $tms{$tm} = "selected"; $tys{$ty} = "selected"; if ($req->param('c-apa') eq 'on') { $cb{'c-apa'} = 'checked'; } if ($req->param('c-art') eq 'on') { $cb{'c-art'} = 'checked'; } if ($req->param('c-bus') eq 'on') { $cb{'c-bus'} = 'checked'; } if ($req->param('c-eng') eq 'on') { $cb{'c-eng'} = 'checked'; } if ($req->param('c-etc') eq 'on') { $cb{'c-etc'} = 'checked'; } if ($req->param('c-for') eq 'on') { $cb{'c-for'} = 'checked'; } if ($req->param('c-hou') eq 'on') { $cb{'c-hou'} = 'checked'; } if ($req->param('c-ibj') eq 'on') { $cb{'c-ibj'} = 'checked'; } if ($req->param('c-iej') eq 'on') { $cb{'c-iej'} = 'checked'; } if ($req->param('c-mar') eq 'on') { $cb{'c-mar'} = 'checked'; } if ($req->param('c-peo') eq 'on') { $cb{'c-peo'} = 'checked'; } if ($req->param('c-res') eq 'on') { $cb{'c-res'} = 'checked'; } if ($req->param('c-web') eq 'on') { $cb{'c-web'} = 'checked'; } if ($req->param('c-wri') eq 'on') { $cb{'c-wri'} = 'checked'; } if ($req->param('c-car') eq 'on') { $cb{'c-car'} = 'checked'; } if ($req->param('c-sys') eq 'on') { $cb{'c-sys'} = 'checked'; } print < craigslist posts per month


from: apartments avaliable art jobs business jobs
to: engineering jobs etcetera jobs for sale
housing wanted internet business jobs internet engineering jobs
people resumes web design jobs
marketing jobs writing jobs



questions? comments? feedback? -- what is this?
commercial reproduction is prohibited

EOT } sub generate_graph { my ($filename) = @_; require Chart::Graph; require Time::Local; $from = Time::Local::timegm(0, 0, 0, 1, $req->param('from_month'), $req->param('from_year')); $to = Time::Local::timegm(0, 0, 0, 1, $req->param('to_month'), $req->param('to_year')); open (IN, "datafile"); while() { ($d, $c, $n) = split /,/; unless ($from < $d && $d < $to) { next; } chomp($n); if ($req->param('c-apa') ne 'on' && $c =~ /^apa/) { next; } if ($req->param('c-art') ne 'on' && $c =~ /^art/) { next; } if ($req->param('c-bus') ne 'on' && $c =~ /^bus/) { next; } if ($req->param('c-eng') ne 'on' && $c =~ /^eng/) { next; } if ($req->param('c-etc') ne 'on' && $c =~ /^etc/) { next; } if ($req->param('c-for') ne 'on' && $c =~ /^for/) { next; } if ($req->param('c-hou') ne 'on' && $c =~ /^hou/) { next; } if ($req->param('c-ibj') ne 'on' && $c =~ /^internet b/) { next; } if ($req->param('c-iej') ne 'on' && $c =~ /^internet e/) { next; } if ($req->param('c-mar') ne 'on' && $c =~ /^mar/) { next; } if ($req->param('c-peo') ne 'on' && $c =~ /^peo/) { next; } if ($req->param('c-res') ne 'on' && $c =~ /^res/) { next; } if ($req->param('c-web') ne 'on' && $c =~ /^web/) { next; } if ($req->param('c-wri') ne 'on' && $c =~ /^wri/) { next; } if ($req->param('c-car') ne 'on' && $c =~ /^car/) { next; } if ($req->param('c-sys') ne 'on' && $c =~ /^sys/) { next; } $category{$c}{$d} = $n; } foreach $c (sort keys %category) { @dates = undef; @cnt = undef; foreach $d (sort keys %{$category{$c}}) { push @dates, $d; push @cnt, $category{$c}{$d}; } push(@data, [{'title' => $c, 'style' => 'lines', 'type' => 'columns'}, [@dates], [@cnt]]); } $r = Chart::Graph::gnuplot({"title" => "Craigslist Postings By Category", "x-axis label" => "Time", "y-axis label" => "Posts", "logscale x" => "1", "output file" => "$filename", "extra_opts" => "set grid\n", "xtics" => [ ["M", Time::Local::timegm(0, 0, 0, 1, 2, 98)], ["A", Time::Local::timegm(0, 0, 0, 1, 3, 98)], ["M", Time::Local::timegm(0, 0, 0, 1, 4, 98)], ["J", Time::Local::timegm(0, 0, 0, 1, 5, 98)], ["J", Time::Local::timegm(0, 0, 0, 1, 6, 98)], ["A", Time::Local::timegm(0, 0, 0, 1, 7, 98)], ["S", Time::Local::timegm(0, 0, 0, 1, 8, 98)], ["O", Time::Local::timegm(0, 0, 0, 1, 9, 98)], ["N", Time::Local::timegm(0, 0, 0, 1, 10, 98)], ["D", Time::Local::timegm(0, 0, 0, 1, 11, 98)], ["99", Time::Local::timegm(0, 0, 0, 1, 0, 99)], ["F", Time::Local::timegm(0, 0, 0, 1, 1, 99)], ["M", Time::Local::timegm(0, 0, 0, 1, 2, 99)], ["A", Time::Local::timegm(0, 0, 0, 1, 3, 99)], ["M", Time::Local::timegm(0, 0, 0, 1, 4, 99)], ["J", Time::Local::timegm(0, 0, 0, 1, 5, 99)], ["M", Time::Local::timegm(0, 0, 0, 1, 4, 99)], ["J", Time::Local::timegm(0, 0, 0, 1, 5, 99)], ["J", Time::Local::timegm(0, 0, 0, 1, 6, 99)], ["A", Time::Local::timegm(0, 0, 0, 1, 7, 99)], ["S", Time::Local::timegm(0, 0, 0, 1, 8, 99)], ["O", Time::Local::timegm(0, 0, 0, 1, 9, 99)], ["N", Time::Local::timegm(0, 0, 0, 1, 10, 99)], ["D", Time::Local::timegm(0, 0, 0, 1, 11, 99)], ["00", Time::Local::timegm(0, 0, 0, 1, 0, 100)], ["F", Time::Local::timegm(0, 0, 0, 1, 1, 100)], ["M", Time::Local::timegm(0, 0, 0, 1, 2, 100)], ["A", Time::Local::timegm(0, 0, 0, 1, 3, 100)], ["M", Time::Local::timegm(0, 0, 0, 1, 4, 100)], ["J", Time::Local::timegm(0, 0, 0, 1, 5, 100)], ["M", Time::Local::timegm(0, 0, 0, 1, 4, 100)], ["J", Time::Local::timegm(0, 0, 0, 1, 5, 100)], ["J", Time::Local::timegm(0, 0, 0, 1, 6, 100)], ["A", Time::Local::timegm(0, 0, 0, 1, 7, 100)], ["S", Time::Local::timegm(0, 0, 0, 1, 8, 100)], ["A", Time::Local::timegm(0, 0, 0, 1, 7, 100)], ["S", Time::Local::timegm(0, 0, 0, 1, 8, 100)], ["O", Time::Local::timegm(0, 0, 0, 1, 9, 100)], ["N", Time::Local::timegm(0, 0, 0, 1, 10, 100)], ["D", Time::Local::timegm(0, 0, 0, 1, 11, 100)], ["01", Time::Local::timegm(0, 0, 0, 1, 0, 101)], ["F", Time::Local::timegm(0, 0, 0, 1, 1, 101)], ["M", Time::Local::timegm(0, 0, 0, 1, 2, 101)], ["A", Time::Local::timegm(0, 0, 0, 1, 3, 101)], ["M", Time::Local::timegm(0, 0, 0, 1, 4, 101)], ["J", Time::Local::timegm(0, 0, 0, 1, 5, 101)], ["M", Time::Local::timegm(0, 0, 0, 1, 4, 101)], ["J", Time::Local::timegm(0, 0, 0, 1, 5, 101)], ["J", Time::Local::timegm(0, 0, 0, 1, 6, 101)], ["A", Time::Local::timegm(0, 0, 0, 1, 7, 101)], ["S", Time::Local::timegm(0, 0, 0, 1, 8, 101)]], },@data); if ($r == 0) { errorpage(); exit(); } } sub errorpage { print<graph render failed

Unable to render the requested graph


Please note the following caveats:
  • Data is only avaliable for dates landing between Mar '98 and Aug '01
  • You cannot graph a single month
  • There might not be any data for the categories you selected during the months you selected. Some categories were deprecated and others were added during the timeline.
  • Perhaps your From time is more recent than your To time
  • There's a bug, email me about it

Click here to try again

EOT }