Skip to content

Commit

Permalink
Use constituency data from main people.json file.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Jul 1, 2024
1 parent d67c8ac commit e84fb06
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions scripts/load-people
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ verbose("Start");
db_connect();

my $pwmembers = mySociety::Config::get('PWMEMBERS');
verbose("Constituencies");
load_constituencies();
verbose("People");
load_people();
verbose("People and Constituencies");
load_people_json();
verbose("Offices");
load_moffices();
check_member_ids();
Expand Down Expand Up @@ -106,8 +104,8 @@ sub load_moffices {
}

sub load_constituencies {
my $j = shift;
my $constituencyadd = $dbh->prepare("replace into constituency (cons_id, name, main_name, from_date, to_date) values (?, ?, ?, ?, ?)");
my $j = decode_json(scalar read_file($pwmembers . 'constituencies.json'));
my $Collator = Unicode::Collate->new(normalization => undef, level => 1);
foreach my $cons (@$j) {
(my $consid = $cons->{id}) =~ s#uk.org.publicwhip/cons/##;
Expand All @@ -121,7 +119,8 @@ sub load_constituencies {

my $main_name = 1;
my %seen;
foreach my $name (@{$cons->{names}}) {
my @names = ($cons->{area}{name}, @{$cons->{area}{other_names} || []});
foreach my $name (@names) {
# need this because this table is using the latin_spanish_ci
# collation and doesn't distinguish between Berwick-upon-Tweed and
# Berwick-Upon-Tweed, or Ynys Mon with/without accent, and so you
Expand All @@ -141,12 +140,17 @@ sub load_constituencies {
}
}

sub load_people {
sub load_people_json {

# disable autocommit to load multiple people and memberships at once
$dbh->{AutoCommit} = 0;

my $j = decode_json(scalar read_file($pwmembers . 'people.json'));

verbose(" Constituencies");
load_constituencies($j->{posts});

verbose(" People");
foreach (@{$j->{organizations}}) {
$organizations{$_->{id}} = $_;
}
Expand Down

0 comments on commit e84fb06

Please sign in to comment.