Skip to content

Commit

Permalink
[2024] Remove DC lookup.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Jul 5, 2024
1 parent e6d45d7 commit 353749b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 72 deletions.
18 changes: 0 additions & 18 deletions www/docs/postcode/address_list.php

This file was deleted.

56 changes: 2 additions & 54 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 Down Expand Up @@ -201,35 +181,11 @@ 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);
Expand All @@ -255,14 +211,6 @@ function mapit_lookup($type, $filename) {
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

0 comments on commit 353749b

Please sign in to comment.