aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorHakim Cassimally <hakim@mysociety.org>2014-03-04 15:12:33 +0000
committerHakim Cassimally <hakim@mysociety.org>2014-04-10 13:47:04 +0000
commit62c2c7c5ee458b8c35c66e6f8992df960eb6f0eb (patch)
tree8467c6fe5ee4aaf486007010a527d53102de62f9 /bin
parentb82228ce014cc87866d976eeb3ce6e454e87c336 (diff)
bin/geocode script for testing geocoding
Run bin/geocode -h for options. Has: * configurable cobrand / config-file / geocoder * some diagnostics for missing cobrand Minor fixes rebased into this commit: * bin/geocode error if no --cobrand passed * bin/geocode docs and accept GEOCODER as string Notable TODOs remaining: * reverse geocoding, to double check that latitude actually maps somewhere useful (and is within Cobrand's boundaries) * diagnosis of relevant CONFIG settings * flag to disable caching
Diffstat (limited to 'bin')
-rwxr-xr-xbin/geocode79
1 files changed, 79 insertions, 0 deletions
diff --git a/bin/geocode b/bin/geocode
new file mode 100755
index 000000000..254cf1578
--- /dev/null
+++ b/bin/geocode
@@ -0,0 +1,79 @@
+#!/usr/bin/perl
+
+=head1 NAME
+
+geocode - commandline tool to test geocoders
+
+=head1 SYNOPSIS
+
+ $ eval `perl setenv.pl`, or call with bin/cron-wrapper
+
+ $ bin/geocode --geocoder=Bing --cobrand=bromley "Glebe Rd"
+
+ # ... if your conf/general.yml supplies GEOCODER:
+ $ bin/geocode --cobrand=bromley "Glebe Rd"
+
+ # ... if you want to use config that you have in conf/general.bing.yml
+ $ bin/geocode --override-config=general.bing --cobrand=bromley "Glebe Rd"
+
+ ## ... output from geocoder
+
+=cut
+
+use strict;
+use warnings;
+require 5.8.0;
+
+use Data::Dumper;
+use Pod::Usage;
+use feature 'say';
+
+use Getopt::Long;
+
+my %options = ( help => sub { pod2usage(0) } );
+
+GetOptions \%options,
+ 'geocoder=s',
+ 'help|h',
+ 'cobrand=s',
+ 'override-config=s';
+
+my $s = join ' ', @ARGV
+ or pod2usage(0);
+
+pod2usage(0) unless $options{cobrand};
+
+local $ENV{FMS_OVERRIDE_CONFIG} = $options{'override-config'} if $options{'override-config'};
+
+eval 'use FixMyStreet';
+eval 'use FixMyStreet::App';
+eval 'use FixMyStreet::Cobrand';
+eval 'use FixMyStreet::Geocode';
+
+mySociety::Locale::gettext_domain( 'FixMyStreet' );
+
+my $geocoder_type = $options{geocoder} || do {
+ my $GEOCODER = FixMyStreet->config('GEOCODER');
+ ref $GEOCODER ? $GEOCODER->{type} : $GEOCODER;
+} or pod2usage(0);
+
+my $geocoder_name = "FixMyStreet::Geocode::${geocoder_type}";
+my $code_ref = $geocoder_name->can('string')
+ or die "$geocoder_name is not a valid geocoder?";
+
+my @allowed_cobrands = FixMyStreet::Cobrand->get_allowed_cobrands();
+
+my $cobrand_name = FixMyStreet::Cobrand->get_class_for_moniker($options{cobrand});
+my $cobrand = $cobrand_name->new();
+
+say "USING COBRAND $cobrand_name";
+if ($cobrand->moniker ne lc($options{cobrand})) {
+ say "!!! asked for $options{cobrand}";
+ say "!!! Check ALLOWED_COBRANDS setting in conf/general.yml (or supplied --override-config file)";
+ say Dumper(\@allowed_cobrands);
+}
+
+my $c = FixMyStreet::App->new();
+$c->stash->{cobrand} = $cobrand;
+
+say Dumper( $code_ref->( $s, $c ) );