#! /usr/bin/perl -w # # tags # PJWindley (May 2006) # www.windley.com # BEGIN{ push(@INC, '/usr/home/windley/usr/local/lib/perl5/site_perl'); } use CGI; use LWP::UserAgent; use HTTP::Request::Common; use HTTP::Response; # config my $tag_cache = "/web/htdocs/technometria/tag_cache"; my $base_url = 'www.windley.com'; my $include_blogs = '11'; my $age = 6*3600; # in seconds # let's go! my $query = new CGI; # get params, if any my $flavor = $query->param('flavor') || 'html'; # get the tag and *only* the tag my $tag = $query->path_info(); $tag =~ s#/([A-Za-z0-9_]+).*#$1#; my $ext; if ($flavor eq 'rss') { $ext = 'rss'; $template = 'rss'; $doc_type = 'application/xml'; } else { $ext = 'html'; $template = 'technometria_tag'; $doc_type = 'text/html'; } my $filename = "tag_cache/$tag.$ext"; my $cached = 1; if (-e "$filename") { @filestat = stat "$filename"; $cached = 0 if ((time - $filestat[9]) > $age); } else { $cached = 0; } if (! $cached) { my $page = run_search($tag); open(TAG,">$filename"); print TAG $page; close TAG; } # put out the HTML header print $query->header(-type=>$doc_type); # cat the file open(TAG, $filename); @lines = ; close(TAG); print @lines; 1; sub run_search { my ($tag) = @_; # make URL my $url = "http://$base_url/mt-search.cgi?Template=$template&IncludeBlogs=$include_blogs&SearchElement=keywords&search=".$tag; # Create a user agent object $ua = LWP::UserAgent->new; $ua->agent("Tagger/0.9a"); # Pass request to the user agent and get a response back $res = $ua->request(GET $url); # Check the outcome of the response my $page; if ($res->is_success) { $page = $res->content; } else { $page = $res->error_as_HTML; } return $page; }