Skip to content

Instantly share code, notes, and snippets.

@hubgit
Last active July 31, 2020 10:09
Show Gist options
  • Save hubgit/5488213 to your computer and use it in GitHub Desktop.
Save hubgit/5488213 to your computer and use it in GitHub Desktop.

Revisions

  1. hubgit revised this gist Apr 30, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion land-registry-sparql.php
    Original file line number Diff line number Diff line change
    @@ -9,12 +9,13 @@
    ));

    $limit = 100000;
    $total = 858848; // COUNT(*)
    $total = 860350; // SELECT COUNT(*) WHERE { ?x a <http://landregistry.data.gov.uk/def/ppi/TransactionRecord> }

    for ($i = 0; $i < $total; $i += $limit) {
    $query = sprintf('
    SELECT ?postcode ?amount ?date ?status
    WHERE {
    ?transx a <http://landregistry.data.gov.uk/def/ppi/TransactionRecord> .
    ?transx <http://landregistry.data.gov.uk/def/ppi/pricePaid> ?amount .
    ?transx <http://landregistry.data.gov.uk/def/ppi/transactionDate> ?date .
    ?transx <http://landregistry.data.gov.uk/def/ppi/propertyAddress> ?addr.
  2. hubgit revised this gist Apr 30, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion land-registry-sparql.php
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    CURLOPT_HTTPHEADER => array('Accept: text/plain'),
    ));

    $limit = 10000;
    $limit = 100000;
    $total = 858848; // COUNT(*)

    for ($i = 0; $i < $total; $i += $limit) {
  3. hubgit revised this gist Apr 30, 2013. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion land-registry-sparql.php
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,6 @@
    $curl = curl_init('http://landregistry.data.gov.uk/landregistry/query');

    curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_VERBOSE => true,
    CURLOPT_ENCODING => 'gzip,deflate',
    CURLOPT_HTTPHEADER => array('Accept: text/plain'),
  4. hubgit created this gist Apr 30, 2013.
    48 changes: 48 additions & 0 deletions land-registry-sparql.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    <?php

    $curl = curl_init('http://landregistry.data.gov.uk/landregistry/query');

    curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_VERBOSE => true,
    CURLOPT_ENCODING => 'gzip,deflate',
    CURLOPT_HTTPHEADER => array('Accept: text/plain'),
    ));

    $limit = 10000;
    $total = 858848; // COUNT(*)

    for ($i = 0; $i < $total; $i += $limit) {
    $query = sprintf('
    SELECT ?postcode ?amount ?date ?status
    WHERE {
    ?transx <http://landregistry.data.gov.uk/def/ppi/pricePaid> ?amount .
    ?transx <http://landregistry.data.gov.uk/def/ppi/transactionDate> ?date .
    ?transx <http://landregistry.data.gov.uk/def/ppi/propertyAddress> ?addr.
    ?transx <http://landregistry.data.gov.uk/def/ppi/recordStatus> ?status.
    ?addr <http://landregistry.data.gov.uk/def/common/postcode> ?postcode .
    }
    LIMIT %d OFFSET %d', $limit, $i);

    $params = array(
    'query' => $query,
    'output' => 'csv',
    );

    $file = gzopen(sprintf('data/%s.csv.gz', $i), 'w');

    curl_setopt_array($curl, array(
    CURLOPT_POSTFIELDS => http_build_query($params),
    CURLOPT_FILE => $file,
    ));

    $result = curl_exec($curl);

    $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    if ($code !== 200) {
    exit("Error: $code\n" . print_r($result, true));
    }

    gzclose($file);
    }