Skip to content

Commit

Permalink
Missed the most important file!
Browse files Browse the repository at this point in the history
  • Loading branch information
theorbtwo committed Feb 8, 2012
1 parent bb03e5e commit d5e1208
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions whereto.pl
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env perl

use strict;
use warnings;

use Web::Simple 'WhereTo::Web';
use lib '/mnt/shared/projects/geo/osm/whereto/lib';
use WhereTo;

{
package WhereTo::Web;

sub dispatch_request {

my $filedir = '/mnt/shared/projects/geo/osm/whereto/data-files/';
sub (GET + ?latitude=&longitude=&distance=) {
my ($self, $lat, $lon, $dist) = @_;
## Would be handy if we could also take a postcode/address.

## Should possibly test the params better:
die "No such Latitude: $lat" if ($lat !~ /^[-\d\.]+[NS]?$/);
die "No such Latitude: $lon" if ($lon !~ /^[-\d\.]+[WE]?$/);
die "Impossible distance $dist" if($dist !~ /^[\d\.]+$/);

## Avoid running twice for same inputs:
my $tsv_file = "${filedir}${lat}x${lon}x${dist}.tsv";
if(-e $tsv_file) {
$tsv_file =~ s{/mnt/shared/projects/geo/osm/whereto/}{};
return [200, [ 'Content-type', 'text/plain' ], [ $tsv_file || '' ] ];
}

my $whereto = WhereTo->new();
$whereto->calculate_paths([$lat, $lon], $dist);
die "No paths found" if(!@{$whereto->{terminals}});

$whereto->write_tsv($tsv_file);
$tsv_file =~ s{/mnt/shared/projects/geo/osm/whereto/}{};

return [200, [ 'Content-type', 'text/plain' ], [ $tsv_file || '' ] ];

}
}
}


WhereTo::Web->run_if_script;

0 comments on commit d5e1208

Please sign in to comment.