Created
June 26, 2024 23:16
-
-
Save dlh3/2229119a7a909890ac7d7847156eea76 to your computer and use it in GitHub Desktop.
BC Liquor Store (SFU) Random Beer Selector
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
// Run in devtools at https://www.bcliquorstores.com/ | |
await (async function randomBeerSelector() { | |
const searchBCL = (category) => | |
fetch(`https://www.bcliquorstores.com/ajax/browse?category=${category}&sort=name.raw:asc&size=10000`) | |
.then(resp => resp.json()) | |
.then(json => json.hits.hits.map(hit => hit._source)); | |
const getInventoryAtSFU = (sku) => | |
fetch(`https://www.bcliquorstores.com/stores/search?format=json&lat=49.277892&lng=-122.909896&rad=1&sku=${sku}`) | |
.then(resp => resp.json()) | |
.then(json => json.stores[0].productAvailability) | |
.catch(() => 0); | |
return searchBCL('beer') | |
.then(async products => { | |
while (true) { | |
let product = products[Math.floor(Math.random() * products.length)]; | |
let inventory = await getInventoryAtSFU(product.sku); | |
if (inventory) { | |
console.log(` | |
Name: ${product.name} | |
Alcohol: ${product.alcoholPercentage}% | |
Packaging: ${product.unitSize} x ${product.volume * 1000}mL | |
Rating: ${product.consumerRating} | |
Style: ${product.style} | |
Description: ${product.tastingDescription.replace(/\s+$/, '')} | |
Country: ${product.countryName} | |
SKU: ${product.sku} | |
Price: $${product.currentPrice} | |
Inventory (SFU): ${inventory} | |
`); | |
return {inventoryAtSFU: inventory, ...product}; | |
} | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment