summaryrefslogtreecommitdiff
path: root/scrape.js
diff options
context:
space:
mode:
Diffstat (limited to 'scrape.js')
-rw-r--r--scrape.js2
1 files changed, 1 insertions, 1 deletions
diff --git a/scrape.js b/scrape.js
index 9f0b5b5..5f6ee9f 100644
--- a/scrape.js
+++ b/scrape.js
@@ -1 +1 @@
-var beers = []; $('.beer-details').each(function(i, b) { b = $(b); var beer = {}; beer['name'] = b.find('.name a').text().trim(); beer['style'] = b.find('.style').text().trim().replace('This beer is no longer being produced by the brewery', '').split(' - '); beer['abv'] = parseFloat(b.next('.details').find('.abv').text()); beer['added'] = b.next('.details').find('.date').text().trim().replace('Added ', '').split('/').map(t => parseInt(t, 10)); beer['rating'] = parseFloat(b.next('.details').find('.num').text().replace('(', '').replace(')','')); beer['ratings'] = parseInt(b.next('.details').find('.raters').text().replace(',','')); beers.push(beer); }); console.log(JSON.stringify(beers));
+var beers = []; $('.beer-details').each(function(i, b) { b = $(b); var noLonger = 'This beer is no longer being produced by the brewery'; var beer = {}; beer['name'] = b.find('.name a').text().trim(); beer['style'] = b.find('.style').text().trim().replace(noLonger, '').split(' - '); beer['in_production'] = b.find('.style').text().indexOf(noLonger) == -1; beer['abv'] = parseFloat(b.next('.details').find('.abv').text()); beer['added'] = b.next('.details').find('.date').text().trim().replace('Added ', '').split('/').map(t => parseInt(t, 10)); beer['rating'] = parseFloat(b.next('.details').find('.num').text().replace('(', '').replace(')','')); beer['ratings'] = parseInt(b.next('.details').find('.raters').text().replace(',','')); beers.push(beer); }); var data = JSON.stringify(beers); var blob = new Blob([data], { type: 'text/json' }), e = document.createEvent('MouseEvents'), a = document.createElement('a'); a.download = location.href.split('/')[3] +'.json'; a.href = window.URL.createObjectURL(blob); a.dataset.downloadurl = ['text/json', a.download, a.href].join(':'); e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); a.dispatchEvent(e);