Skip to content

Commit

Permalink
[2024] Remove DC lookup, revert to previous setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Jul 5, 2024
1 parent e6d45d7 commit da10dbc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 172 deletions.
32 changes: 0 additions & 32 deletions markdown/post-election.md

This file was deleted.

18 changes: 0 additions & 18 deletions www/docs/postcode/address_list.php

This file was deleted.

73 changes: 3 additions & 70 deletions www/docs/postcode/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,11 @@

# 2024 ELECTION EXTRA

$data['address'] = $address = get_http_var('address');
if ($address) {
$dc_data = democracy_club_address($address);
$constituencies = mapit_address($address, $pc);
} else {
$dc_data = democracy_club_postcode($pc);
if (!isset($dc_data->error) && $dc_data->address_picker) {
show_address_list($pc, $dc_data->addresses);
exit;
}
$constituencies = mapit_postcode($pc);
}
if (!$constituencies || isset($dc_data->error) || !$dc_data->dates) {
$constituencies = mapit_postcode($pc);
if (!$constituencies) {
postcode_error("Sorry, " . _htmlentities($pc) . " isn't a known postcode");
}

$data['ballot'] = null;
foreach ($dc_data->dates as $date) {
if ($date->date != '2024-07-04') continue;
foreach ($date->ballots as $b) {
if ($b->election_id != 'parl.2024-07-04') continue;
$data['ballot'] = $b;
}
}

if (isset($constituencies['SPE']) || isset($constituencies['SPC'])) {
$data['multi'] = "scotland";
$MEMBER = fetch_mp($pc, $constituencies);
Expand All @@ -64,17 +44,9 @@
} else {
$data['multi'] = "uk";
$MEMBER = fetch_mp($pc, $constituencies, 1);
$data['mp'] = [
'name' => $MEMBER->full_name(),
'person_id' => $MEMBER->person_id(),
'constituency' => $MEMBER->constituency(),
'former' => !$MEMBER->current_member(HOUSE_TYPE_COMMONS),
'standing_down_2024' => $MEMBER->extra_info['standing_down_2024'] ?? '',
];
$data['MPSURL'] = new \MySociety\TheyWorkForYou\Url('mps');
member_redirect($MEMBER);
}

$data['mapit_ids'] = $mapit_ids;
MySociety\TheyWorkForYou\Renderer::output('postcode/index', $data);

# ---
Expand Down Expand Up @@ -201,37 +173,12 @@ function member_redirect(&$MEMBER) {
}
}

function democracy_club_postcode($pc) {
$pc = urlencode($pc);
$data = web_lookup("https://developers.democracyclub.org.uk/api/v1/postcode/$pc/?include_current=1&auth_token=" . OPTION_DEMOCRACYCLUB_TOKEN);
$data = json_decode($data);
return $data;
}

function democracy_club_address($address) {
$address = urlencode($address);
$data = web_lookup("https://developers.democracyclub.org.uk/api/v1/address/$address/?include_current=1&auth_token=" . OPTION_DEMOCRACYCLUB_TOKEN);
$data = json_decode($data);
return $data;
}

function mapit_postcode($postcode) {
$filename = 'postcode/' . rawurlencode($postcode);
return mapit_lookup('postcode', $filename);
}

function mapit_address($address, $pc) {
$address = urlencode($address);
$url = str_replace('{s}', $address, OPTION_MAPIT_UPRN_LOOKUP);
$file = web_lookup($url);
$r = json_decode($file);
if (isset($r->error)) return mapit_postcode($pc);
$filename = 'point/4326/' . $r->wgs84_lon . ',' . $r->wgs84_lat;
return mapit_lookup('point', $filename);
}

function mapit_lookup($type, $filename) {
global $mapit_ids;
$file = web_lookup(OPTION_MAPIT_URL . $filename);
$r = json_decode($file);
if (isset($r->error)) return '';
Expand All @@ -242,27 +189,13 @@ function mapit_lookup($type, $filename) {
foreach ($input as $row) {
if (in_array($row->type, array('WMC', 'WMCF', 'SPC', 'SPE', 'NIE', 'WAC', 'WAE')))
$areas[$row->type] = $row->name;
if ($row->type == 'WMC') {
$mapit_ids['old'] = $row->id;
}
if ($row->type == 'WMCF') {
$mapit_ids['new'] = $row->id;
}
}
if (!isset($areas['WMC'])) {
return '';
}
return $areas;
}

function show_address_list($pc, $addresses) {
global $PAGE;
$PAGE->page_start();
$PAGE->stripe_start();
include("address_list.php");
$PAGE->page_end();
}

function web_lookup($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Expand Down

This file was deleted.

17 changes: 8 additions & 9 deletions www/includes/easyparliament/templates/html/postcode/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,8 @@ function member_image_box(string $person_id, string $person_url, string $person_
}
}

include "ge2024-post-election.php";

# The below is normally the main column, but for now let us make it the sidebar...


?>

</div>
<div class="sidebar">
<div class="block">

<div id="current">
<h2><?= gettext('Your representatives') ?></h2>
<ul>
Expand Down Expand Up @@ -127,6 +118,14 @@ function member_image_box(string $person_id, string $person_url, string $person_

echo '</div>';

?>

</div>
<div class="sidebar">
<div class="block">

<?php

include("repexplain.php");

?>
Expand Down

0 comments on commit da10dbc

Please sign in to comment.