-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
77 lines (71 loc) · 2.09 KB
/
Copy pathindex.js
File metadata and controls
77 lines (71 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Parser } from '@json2csv/plainjs';
import axios from 'axios';
import fs from 'fs';
let establishments = [];
const nameFilter = [
'Elior',
'Lexington',
'Taylor Shaw',
'Caterplus',
'Edwards and Blake',
'Genuine Dining',
'Wilson Vale',
'Bartlett Mitchell',
'ISS',
'RA group',
'Levy',
'Chartwells',
'Eurest',
'14Forty',
'Compass',
'Baxter Storey',
'Grazing',
'OCS',
'Thomas Franks',
'Atalian Servest',
'Bennet Hay',
'CH&Co',
'Vacherin',
'KSG',
'Fooditude',
'Connect Vending',
];
const getAuthorityIds = async () => {
const authorities = await axios.get('https://api.ratings.food.gov.uk/Authorities/basic', { headers: {
"x-api-version": 2,
}});
return authorities.data.authorities.map(authority => authority.LocalAuthorityId);
}
const getEstablishments = async () => {
const authorityIds = await getAuthorityIds();
for (const authorityId of authorityIds) {
const authorityEstabilshments = await axios.get(`https://api.ratings.food.gov.uk/Establishments/?localAuthorityId=${authorityId}&businessTypeId=1`, { headers: {
"x-api-version": 2,
}});
const transformedEstablishments = authorityEstabilshments.data.establishments.map(
({ BusinessName , BusinessType, BusinessTypeID, AddressLine1, AddressLine2, AddressLine3, AddressLine4, PostCode, Phone }) => {
return { BusinessName , BusinessType, BusinessTypeID, AddressLine1, AddressLine2, AddressLine3, AddressLine4, PostCode, Phone };
})
const filteredEstablishments = transformedEstablishments.filter(establishment => {
for(const name of nameFilter) {
if (establishment.BusinessName.includes(name)) {
return true;
}
}
return false;
})
establishments = establishments.concat(filteredEstablishments);
console.log(`Finished authority ID: ${authorityId}`);
}
}
const createCSV = async () => {
await getEstablishments();
try {
const parser = new Parser();
const csv = parser.parse(establishments);
fs.writeFileSync('fsa-establishments.csv', csv);
} catch (err) {
console.log(err);
}
}
createCSV();