Start writing procesor for the authority areas
2 files changed, 78 insertions(+), 7 deletions(-)

A => bin/overham/ccimport.pl
M input.txt
A => bin/overham/ccimport.pl +78 -0
@@ 0,0 1,78 @@ 
+#!/usr/bin/env perl
+
+use IO::File;
+use English;
+use Readonly;
+use Data::Dumper;
+use strict;
+use warnings;
+
+Readonly my $FILE => 'input.txt';
+
+sub main {
+	my @lines;
+	my $file = IO::File->new($FILE, 'r');
+	my %info;
+
+	if ($file) {
+		while (defined(my $line = <$file>)) {
+			if ($line =~ m/^GB-/) {
+				chomp($line);
+				push(@lines, $line);
+			}
+		}
+	} else {
+		printf(STDERR "Cannot open '%s' - %s\n", $FILE, $ERRNO);
+		return 1;
+	}
+
+	if (scalar(@lines)) {
+		my $successCount = processLines(\@lines, \%info);
+		if ($successCount == scalar(@lines)) {
+			printf(STDERR "Success! %d entities processed\n", scalar(@lines));
+			print Dumper \%info;
+			return 0;
+		} elsif ($successCount < scalar(@lines)) {
+			printf(STDERR "Only %d of %d entries were great success\n",
+			    $successCount, scalar(@lines));
+
+			return 1;
+		} else {
+			print("Too many entities processed\n");
+			return 1;
+		}
+	} else {
+		print(STDERR "Nothing to do!\n");
+		return 1;
+	}
+
+}
+
+sub processLines {
+	my ($lines, $info) = @_;
+	my $lineCount = 0;
+
+	foreach my $line (@$lines) {
+		if ($line =~ m/^GB-([A-Z]+)\s+(.*)/) {
+			my $ident = "GB-$1";
+			my $fullDesc = $2;
+			if ($info->{$ident}) {
+				warn("$ident already seen -- ignoring\n");
+			} else {
+				if ($fullDesc) {
+					$info->{$ident}->{fullDesc} = $fullDesc;
+					$lineCount++;
+				} else {
+					$info->{$ident}->{error} = 'Seen but invalid';
+					warn(sprintf("'%s' %s", $ident, $info->{$ident}->{error}));
+				}
+			}
+		} else {
+			warn "Invalid line: $line\n";
+		}
+	}
+
+	return $lineCount;
+}
+
+exit(main());

          
M input.txt +0 -7
@@ 278,14 278,7 @@ GB-GSY Guernsey (see ISO 3166-2:GG)
 GB-JSY Jersey (see ISO 3166-2:JE)
 Newsletter I-9	2007-11-28	Modification of administrative structure	
 Newsletter II-2	2010-06-30	Update and reorganization of the subdivision data and update of the list source	Subdivisions added:
-GB-BDF Bedford
-GB-CBF Central Bedfordshire
-GB-CHE Cheshire East
-GB-CHW Cheshire West and Chester
 Subdivisions deleted:
-GB-BDF Bedfordshire
-GB-CHS Cheshire
-GB-IOS Isles of Scilly
 Newsletter II-3	2011-12-13
 (corrected
 2011-12-15)	NL II-2 correction for administrative name changes.	Status change: