aboutsummaryrefslogtreecommitdiffstats
path: root/bin/emptyhomes
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2015-01-19 16:20:55 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2015-01-19 16:35:36 +0000
commit2e8df1a5a6610c43e0c1bda15d018fa16738061b (patch)
treee06b0a33d399caf5ba0fb94186f609617496740e /bin/emptyhomes
parent7fa239a9c2122074bb65bbb0ac7d30d922a4f761 (diff)
Tidy up of bin directory.
Remove some unneeded scripts, move others to cobrand-specific directories.
Diffstat (limited to 'bin/emptyhomes')
-rwxr-xr-xbin/emptyhomes/canonicalise-eha80
-rwxr-xr-xbin/emptyhomes/make_welsh_po114
2 files changed, 194 insertions, 0 deletions
diff --git a/bin/emptyhomes/canonicalise-eha b/bin/emptyhomes/canonicalise-eha
new file mode 100755
index 000000000..1030982fa
--- /dev/null
+++ b/bin/emptyhomes/canonicalise-eha
@@ -0,0 +1,80 @@
+#!/usr/bin/perl -w
+
+# canonicalise-eha:
+# Convert provided TSV file into one with standard names for MaPit
+#
+# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
+#
+# $Id: canonicalise-eha,v 1.1 2009-05-27 11:11:18 matthew Exp $
+
+use strict;
+require 5.8.0;
+
+# Horrible boilerplate to set up appropriate library paths.
+use FindBin;
+use lib "$FindBin::Bin/../perllib";
+use lib "$FindBin::Bin/../commonlib/perllib";
+
+use mySociety::Config;
+use mySociety::MaPit;
+use mySociety::VotingArea;
+
+BEGIN {
+ mySociety::Config::set_file("$FindBin::Bin/../conf/general");
+ mySociety::MaPit::configure();
+}
+
+my %councils;
+open(FP, "$FindBin::Bin/../data/eha_listN");
+while (<FP>) {
+ s/\r?\n//g;
+ my ($name, $email) = split /\s*\t+\s*/;
+ $email ||= '';
+ #$name = 'Blackburn' if $name eq 'Blackburn with Darwen';
+ $name =~ s/^St /St. /;
+ $name =~ s/-(upon|on|le)-/ $1 /;
+ $name =~ s/^LB //;
+ $name =~ s/ BC| DC| MDC| MBC| (Metropolitan|Borough|District|County|City) Council| Council//;
+ print "Already have $name\n" if $councils{$name};
+ $councils{$name} = $email;
+}
+close(FP);
+
+my @types = grep { $_ !~ /CTY|LGD/ } @$mySociety::VotingArea::council_parent_types;
+my (%out);
+foreach my $type (@types) {
+ my $areas = mySociety::MaPit::get_areas_by_type($type);
+ my $areas_info = mySociety::MaPit::get_voting_areas_info($areas);
+ foreach my $id (keys %$areas_info) {
+ my $area_info = $areas_info->{$id};
+ next if $area_info->{country} eq 'S';
+ my $name = $area_info->{name};
+ if ($name eq 'Durham City Council') {
+ $out{$id} = $councils{'Durham City'};
+ delete $councils{'Durham City'};
+ next;
+ #} elsif ($name eq 'Durham County Council') {
+ # $out{$id} = $councils{'Durham County'};
+ # next;
+ }
+ $name =~ s/( (Borough|City|District|County))* Council//;
+ if ($councils{$name} && $councils{$name} =~ /@/) {
+ $out{$id} = $councils{$name};
+ delete $councils{$name};
+ } else {
+ print "Problem: $name $area_info->{country}\n";
+ }
+ }
+}
+
+foreach (sort keys %councils) {
+ print "Not matched: $_ $councils{$_}\n";
+}
+
+# Output emails to canonical CSV
+open(FP, ">$FindBin::Bin/../data/eha.csv");
+foreach (sort keys %out) {
+ print FP "$_," . $out{$_} . "\n";
+}
+close FP;
diff --git a/bin/emptyhomes/make_welsh_po b/bin/emptyhomes/make_welsh_po
new file mode 100755
index 000000000..a85e7c35b
--- /dev/null
+++ b/bin/emptyhomes/make_welsh_po
@@ -0,0 +1,114 @@
+#!/usr/bin/perl -w
+use strict;
+
+# Given a translation of the Empty Homes version of the FixMyStreet .po file,
+# fix it all up to go direct from FixMyStreet -> EH translation.
+
+use POSIX;
+use FindBin;
+use lib "$FindBin::Bin/../../perllib";
+use PoChange;
+
+chdir("$FindBin::Bin/../../locale");
+
+# First read in translation and match up.
+open(INPO, 'cy_GB.UTF-8/LC_MESSAGES/EmptyHomes.po') or die $!;
+
+my $state = 'start';
+my $msgid = '';
+my $fuzzy = 0;
+my $msgstr;
+my %lookup;
+while (<INPO>) {
+ if (m/^#, fuzzy/) {
+ $fuzzy = 1;
+ } elsif (m/^#/) {
+ # comment or blank line
+ } elsif (m/^\s+$/) {
+ # blank line separates translations
+ $msgid =~ s/"\n"//g;
+ $lookup{$msgid} = [ $msgstr, $fuzzy ];
+ $state = 'msgid';
+ $msgid = "";
+ $fuzzy = 0;
+ } elsif ($state eq 'msgid' && (m/^msgstr "/ || m/^msgstr\[0\] "/)) {
+ $msgstr = $_;
+ $state = 'msgstr';
+ } elsif ($state eq 'msgstr') {
+ $msgstr .= $_;
+ } elsif ($state eq 'msgid') {
+ $msgid .= $_;
+ }
+}
+$lookup{$msgid} = [ $msgstr, $fuzzy ];
+close INPO;
+
+mkdir("en_GB.UTF-8");
+mkdir("en_GB.UTF-8/LC_MESSAGES");
+mkdir("cy_GB.UTF-8");
+mkdir("cy_GB.UTF-8/LC_MESSAGES");
+
+open(MAINPO, 'FixMyStreet.po') or die;
+open(OUTPO, ">cy_GB.UTF-8/LC_MESSAGES/FixMyStreet-EmptyHomes.po") or die;
+
+print OUTPO "# AUTOMATICALLY GENERATED by make_welsh_po, do not edit\n\n";
+
+my $buffer = "";
+my $start = 0;
+while(<MAINPO>) {
+ if (!$start) {
+ s/#, fuzzy/#/;
+ }
+ if (m/"Last-Translator: FULL NAME/) {
+ $_ = '"Last-Translator: mysociety/bin/emptyhomes/make_welsh_po\\n"'."\n";
+ }
+ if (m/"PO-Revision-Date: YEAR-MO-DA/) {
+ my $time = POSIX::strftime("%Y-%m-%d %H:%M%z", localtime(time()));
+ $_ = '"PO-Revision-Date: '.$time.'\\n"'."\n";
+ }
+ if (m/"Language-Team: LANGUAGE/) {
+ $_ = '"Language-Team: mySociety\\n"'."\n";
+ }
+ if (m/"Plural-Forms: nplurals=/) {
+ $_ = '"Plural-Forms: nplurals=2; plural=n != 1;\\n"'."\n";
+ }
+
+ if (m/^#/) {
+ # comment or blank line
+ print OUTPO $_;
+ } elsif (m/^\s+$/) {
+ # blank line
+ $start = 1;
+ $buffer = "";
+ print OUTPO $_;
+ } elsif ($start && (m/^msgstr "/ || m/^msgstr\[0\] "/)) {
+ # start of translated text - translate English into Empty Homes language
+ my $new_buffer = PoChange::fixmystreet_to_reportemptyhomes($buffer);
+ $new_buffer =~ s/"\n"//g;
+
+ if ($lookup{$new_buffer} && $lookup{$new_buffer}[1]) {
+ print OUTPO "#, fuzzy\n";
+ }
+
+ print OUTPO $buffer;
+ if ($lookup{$new_buffer}) {
+ print OUTPO $lookup{$new_buffer}[0];
+ } else {
+ if (m/^msgstr\[0\] ""/) {
+ $new_buffer =~ s/^msgid "/msgstr[0] "/m;
+ $new_buffer =~ s/^msgid_plural "/msgstr[1] "/m;
+ $_ = <MAINPO>; # skip untranslated plural
+ } else {
+ $new_buffer =~ s/^msgid "/msgstr "/;
+ }
+ print OUTPO $new_buffer;
+ }
+
+ $buffer = "";
+ } elsif (!$start) {
+ print OUTPO $_;
+ } else {
+ $buffer .= $_;
+ }
+}
+