I am trying to setup a perl script to read/display a JSON feed from Indeed. It works fine in a PHP script, but not this setup. I need to use Perl in this instance, and also using Text::FastTemplate. Any ideas? I am fairly new to Perl. Thanks.
My other variation looks like this which does not work either...Code:#!/usr/bin/perl use JSON qw( decode_json ); use Data::Dumper; use LWP::Simple; use Text::FastTemplate; $dir = "/templates/jobs"; $useragent = "$ENV{'HTTP_USER_AGENT'}"; $userip = "$ENV{'REMOTE_ADDR'}"; $url = "http://api.indeed.com/ads/apisearch?publisher=xxxxxxxx&q=&l=&sort=&radius=&st=&jt=&start=&limit=10&fromage=10&filter=1&latlong=1&co=us&chnl=&userip=$userip&useragent=$useragent&v=2&format=json"; $jobs = get($url); $data = decode_json($jobs); foreach $job ($data->{'results'}->['result']) { $date = $job->{'date'}; $jobtitle = $job->{'jobtitle'}; $joburl = $job->{'url'}; $company = $job->{'company'}; my (%data) = ( 'DATE' => $date, 'JOBTITLE' => $jobtitle, 'JOBURL' => $joburl, 'COMPANY' => $company ); } my $template = new Text::FastTemplate(file=> 'test.tpl.html', path=> $dir); print "Content-Type: text/html\n\n"; print $template->output( %data ); 1;
test.tpl.htmlCode:#!/usr/bin/perl use JSON qw( decode_json ); use Data::Dumper; use LWP::Simple; use Text::FastTemplate; $dir = "/templates/jobs"; $useragent = "$ENV{'HTTP_USER_AGENT'}"; $userip = "$ENV{'REMOTE_ADDR'}"; $url = "http://api.indeed.com/ads/apisearch?publisher=xxxxxxxx&q=&l=&sort=&radius=&st=&jt=&start=&limit=10&fromage=10&filter=1&latlong=1&co=us&chnl=&userip=$userip&useragent=$useragent&v=2&format=json"; $jobs = get($url); $data = decode_json($jobs); foreach $job ($data->{'results'}->['result']) { $date = $job->{'date'}; $jobtitle = $job->{'jobtitle'}; $joburl = $job->{'url'}; $company = $job->{'company'}; $jobz[$#jobz + 1] = { 'JOB' => 1, 'DATE' => $date, 'JOBTITLE' => $jobtitle, 'JOBURL' => $joburl, 'COMPANY' => $company }; } my $template = new Text::FastTemplate(file=> 'test.tpl.html', path=> $dir); my (%data) = ( 'JOBZ' => $jobz ); print "Content-Type: text/html\n\n"; print $template->output( %data ); 1;
HTML Code:<html> <body> <table> #for ##JOBZ## #if ##JOB## <tr> <td>##DATE##</td> <td><a href="##JOBURL##">##JOBTITLE##</a></td> <td>##COMPANY##</td> </tr> #endif #endfor </table> </body> </html>


Reply With Quote


Bookmarks