Created
September 28, 2021 01:12
-
-
Save kylebarron/8737fb1f95c946d7862f5ecf866a6af9 to your computer and use it in GitHub Desktop.
Average of orucase reviews
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
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