#!/usr/local/bin/perl
# quick and dirty rss
use CGI;
use XML::RSS;
use URI::Escape;
use strict;
require 'cp_common.pl';
require 'search_common.pl';
my $cgi = new CGI();
my $cat = $cgi->param('cat') || 'cp';
my $itm = $cgi->param('itm');
my $fil = $cgi->param('fil');
my $q = $cgi->param('q');
my $loc = $cgi->param('loc');
my $zip = $cgi->param('zip');
my $rad = $cgi->param('rad');
$q = $itm if ($itm);
$q .= ' ' . $fil if ($fil);
my $ps = $cgi->param('ps');
my $pe = $cgi->param('pe');
# validate ps, pe
if ($pe) {
if ($ps =~ /(\d+(?:\.\d+)?)/) {
$ps = $1;
} else {
$ps = 0;
}
if ($pe =~ /(\d+(?:\.\d+)?)/) {
$pe = $1;
} else {
$ps = undef;
$pe = undef;
}
} else {
$ps = undef;
$pe = undef;
}
if ($ps && $pe) {
if ($ps > $pe) {
my $tmp = $pe;
$pe = $ps;
$ps = $tmp;
}
$q .= ' $' . $ps . '-' . $pe;
}
my $ys = $cgi->param('ys');
my $ye = $cgi->param('ye');
if ($ys && $ye) {
if ($ys > $ye) {
my $tmp = $ye;
$ye = $ys;
$ys = $tmp;
}
$q .= ' ' .$ys . '-' . $ye;
}
my ($sec, $min, $hour, $mday, $mon, $year) = localtime(time);
$year += 1900;
$mon += 1;
$mon = '0'.$mon if ($mon < 10);
$mday = '0'.$mday if ($mday < 10);
$hour = '0'.$hour if ($hour < 10);
$min = '0'.$min if ($min < 10);
my $dt = "$year-$mon-$mday" . "T$hour:$min:00-06:00";
my $rss = new XML::RSS (version => '1.0');
$rss->channel(
title => "JaxedMASH $q $loc",
link => "http://www.jaxed.com/search/?q=$q\&cat=$cat\&loc=$loc",
description => "JaxedMASH $q $loc",
dc => {
date => $dt,
subject => "JaxedMASH $q $loc",
creator => 'mash@jaxed.com',
publisher => 'mash@jaxed.com',
rights => 'Copyright 2012',
language => 'en-us',
},
syn => {
updatePeriod => "hourly",
updateFrequency => "1",
#updateBase => "1901-01-01T00:00+00:00",
},
);
my @data;
my $NUM = 25;
my $path = "/www/work/$cat";
my $shmpath = "/dev/shm/$cat";
$path = $shmpath if (-e $shmpath);
my $pathstr = $path . '/*';
### SEARCH!
#my ($dat, $prc, $dt, $img, $loc, $site, $avgstr) = do_search_zip($pathstr, $q, $loc, $zip, $rad, '', '', '', '', undef, $NUM);
my ($dat, $prc, $dt, $img, $loc, $site, $avgstr) = do_search($pathstr, $q, $loc, '','','','',undef);
my $idx = 0;
foreach my $url (sort {$dt->{$b} <=> $dt->{$a}} keys %{$dat}) {
next unless ($idx < $NUM);
$idx++;
my $title = $dat->{$url};
my $price = $prc->{$url};
my $img = $img->{$url};
my $loc = $loc->{$url};
my $site = $site->{$url};
## date
my $prettydt = pretty_date($dt->{$url});
my $idx_dt = '';
if ($dt->{$url} =~ /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/) {
$idx_dt = "$1-$2-$3" ."T$4:$5:00-06:00";
} elsif ($dt->{$url} =~ /(\d\d\d\d)(\d\d)(\d\d)/) {
$idx_dt = "$1-$2-$3" ."T00:00:00-06:00";
}
## image
my $image = '';
$image = "" if ($img =~ /\.[jpg|jpeg|gif|png]/i);
## remove CL
# $url =~ s/\{(.*?)\}//g;
## use CL
if ($url =~ /\{(.*?)\}/) {
$url = $1;
}
if ($url =~ /rover/) {
$url = 'http://www.jaxed.com/cgi-bin/r.cgi?u=' . uri_escape($url);
}
my $loct = get_state($loc);
$loc = $loct if ($loct ne '??');
my $uber_desc = "$title
Site: $site
Location: $loc
Price: $price
[source]
$image";
$rss->add_item(
mode => "append",
title => "$title",
link => "$url",
description => "$uber_desc",
dc => {
creator => "",
date => "$idx_dt"
}
);
}
print "Content-type: application/rss+xml\n\n";
print $rss->as_string;