summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2021-01-19 12:16:26 +0100
committeremkael <emkael@tlen.pl>2021-01-19 12:16:26 +0100
commit0cad52070819091c04eea364673c9c3c7a043bf3 (patch)
tree0f15a5e9bd3ab999526caef38a3ee8acd63fe024
Data retrieval scripts
-rw-r--r--compile.py29
-rw-r--r--scrape.js1
-rw-r--r--styles.py13
3 files changed, 43 insertions, 0 deletions
diff --git a/compile.py b/compile.py
new file mode 100644
index 0000000..cb421b5
--- /dev/null
+++ b/compile.py
@@ -0,0 +1,29 @@
+import json
+import sys
+
+compiled = []
+
+for json_file in sys.argv[1:]:
+ jfile = json.load(open(json_file))
+ for beer in jfile:
+ year = 2000 + beer['added'][2]
+ month = beer['added'][0]
+ brewery = json_file.split('.')[0]
+ name = beer['name']
+ style = beer['style']
+ abv = beer['abv']
+ ratings = beer['ratings']
+ av_rating = beer['rating']
+ if (ratings >= 15) and (av_rating is not None) and (abv is not None):
+ compiled.append({
+ 'year': year,
+ 'month': month,
+ 'brewery': brewery,
+ 'name': name,
+ 'style': style,
+ 'abv': abv,
+ 'ratings': ratings,
+ 'average': av_rating
+ })
+
+print(json.dumps(compiled))
diff --git a/scrape.js b/scrape.js
new file mode 100644
index 0000000..9f0b5b5
--- /dev/null
+++ b/scrape.js
@@ -0,0 +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));
diff --git a/styles.py b/styles.py
new file mode 100644
index 0000000..986e55a
--- /dev/null
+++ b/styles.py
@@ -0,0 +1,13 @@
+import json
+import sys
+
+compiled = []
+
+jfile = json.load(open(sys.argv[1]))
+for beer in jfile:
+ style = ' - '.join(beer['style'])
+ compiled.append(style)
+
+compiled = sorted(list(set(compiled)))
+
+print(json.dumps(compiled))