Skip to content

Instantly share code, notes, and snippets.

@kylebarron
Created September 28, 2021 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylebarron/8737fb1f95c946d7862f5ecf866a6af9 to your computer and use it in GitHub Desktop.
Save kylebarron/8737fb1f95c946d7862f5ecf866a6af9 to your computer and use it in GitHub Desktop.
Average of orucase reviews
import requests
import re
# Airport ninja
# product_id = '163194625'
# n_pages = 63
# B2
product_id = '3776320176181'
n_pages = 17
data = []
for i in range(1, n_pages + 1):
url = f'https://productreviews.shopifycdn.com/proxy/v4/reviews?page={i}&product_id=163194625&shop=orucase.myshopify.com&product_ids%5B%5D={product_id}'
r = requests.get(url)
data.append(r.json())
regex = r'([0-5]) of 5 stars'
stars = []
for result in data:
stars.extend(re.findall(regex, result['reviews']))
stars = list(map(int, stars))
sum(stars) / len(stars)
# 4.525477707006369 for airport ninja
# 4.588235294117647 for B2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment