-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
14,266 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/*-all.zip | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PLACES_API_KEY = TBD |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// run: `$ node --env-file=.env --experimental-fetch fetch.js | ||
// the standard "Fetch" API is only available experimentally in Node, with the above flag we can make it available. | ||
// handy command line infos: https://nodejs.org/en/learn/command-line/output-to-the-command-line-using-nodejs | ||
|
||
const fs = require('node:fs'); | ||
|
||
console.log(process.env["PLACES_API_KEY"]); | ||
return; | ||
|
||
function amexMerchantsToPlaces(amexApiMerchants) { | ||
return amexApiMerchants.flatMap(amexMerchant => { | ||
if (amexMerchant.isMerchantGroup) { | ||
// this happens when there is a "merchantGroup"; | ||
// like Gordon Ramsey etc. Those have a sub node in ".merchants" | ||
// that again look like the merchants on the first level. | ||
// We have to make a recursion here (yay), like: | ||
console.log("Merchant group!", amexMerchant.name); | ||
return amexMerchantsToPlaces(amexMerchant.merchants); | ||
} | ||
return { | ||
"name": amexMerchant.name, | ||
"address": amexMerchant.address, | ||
"zip": amexMerchant.postcode, | ||
"city": amexMerchant.city.title, | ||
"googlePlaceTextQuery": `${amexMerchant.name}, ${amexMerchant.address}, ${amexMerchant.postcode} ${amexMerchant.city.title}`, | ||
"amexRaw": amexMerchant, | ||
} | ||
}); | ||
} | ||
|
||
|
||
const placesPromises = | ||
["GB"].map(async function(country) { | ||
const amexApiMerchants = await ( | ||
await fetch( | ||
`https://dining-offers-prod.amex.r53.tuimedia.com/api/country/${country}/merchants`)) | ||
.json(); | ||
return {country: country, places: amexMerchantsToPlaces(amexApiMerchants)}; | ||
} | ||
); | ||
|
||
const places = {}; | ||
|
||
Promise.all(placesPromises).then(placesInCountries => { | ||
placesInCountries.forEach(placesPerCountry => { | ||
const { country, places: countryPlaces } = placesPerCountry; | ||
places[country] = countryPlaces; | ||
}); | ||
fs.writeFile('./places.json', JSON.stringify(places, null, 2), error => error && console.error(error)); | ||
console.info("All places written successfully."); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.