Skip to content

Commit 2fafca1

Browse files
authored
Remove downloading/parsing of GB postal codes (not useful)
1 parent 5659100 commit 2fafca1

File tree

1 file changed

+0
-41
lines changed

1 file changed

+0
-41
lines changed

api/src/models/postal-codes.js

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable no-await-in-loop, no-restricted-syntax */
22

3-
import AdmZip from 'adm-zip';
43
import csvParse from 'csv-parse';
54
import EventEmitter from 'events';
65
import fetch from 'node-fetch';
@@ -25,46 +24,6 @@ class PostalCodesDataContainer extends EventEmitter {
2524

2625
const data = [];
2726

28-
// 🇬🇧 Load and transform official postal code data as a CSV file from National Statistics Postcode Lookup
29-
// https://geoportal.statistics.gov.uk/datasets/19fac93960554b5e90840505bd73917f
30-
31-
logger.info('Downloading Postal Codes Data for GB…');
32-
const gbResponse = await fetch(
33-
'https://www.arcgis.com/sharing/rest/content/items/19fac93960554b5e90840505bd73917f/data'
34-
);
35-
36-
if (!gbResponse.ok) {
37-
throw new Error(gbResponse.error);
38-
}
39-
40-
const gbData = Buffer.from(await gbResponse.arrayBuffer());
41-
42-
// We are only interested in entries in the “Data/multi_csv” directory of the zip file
43-
const gbZip = new AdmZip(gbData);
44-
const gbZipEntries = gbZip.getEntries();
45-
46-
logger.info('Parsing Postal Codes Data for GB…');
47-
for (const zipEntry of gbZipEntries) {
48-
if (zipEntry.entryName.match(new RegExp('^Data/multi_csv/.*.csv'))) {
49-
// Transform CSV entries to an array of objects with column names as keys
50-
// Header of the CSV files for GB:
51-
// pcd,pcd2,pcds,dointr,doterm,usertype,oseast1m,osnrth1m,osgrdind,oa11,cty,ced,laua,ward,hlthau,nhser,ctry,rgn,pcon,eer,teclec,ttwa,pct,nuts,park,lsoa11,msoa11,wz11,ccg,bua11,buasd11,ru11ind,oac11,lat,long,lep1,lep2,pfa,imd,calncv,stp
52-
// Expected output:
53-
// [{ pcd: "AB1 0AA", pcd2: "AB1 0AA", pcds: "AB1 0AA", … }, …]
54-
const gbCsvEntries = await csvParseAsync(zipEntry.getData(), {
55-
skip_lines_with_empty_values: true,
56-
columns: true,
57-
});
58-
59-
for (const entry of gbCsvEntries) {
60-
data.push({
61-
postalCode: entry.pcds,
62-
countryCode: 'GB',
63-
});
64-
}
65-
}
66-
}
67-
6827
// 🇫🇷️ Load and transform official postal code data as a CSV file from La Poste
6928
// https://datanova.legroupe.laposte.fr/explore/dataset/laposte_hexasmal/export/
7029

0 commit comments

Comments
 (0)