Skip to content

Instantly share code, notes, and snippets.

@merlijn-sebrechts
Last active July 16, 2021 14:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merlijn-sebrechts/06b3ea47f36575896d151c8366fd9e87 to your computer and use it in GitHub Desktop.
Save merlijn-sebrechts/06b3ea47f36575896d151c8366fd9e87 to your computer and use it in GitHub Desktop.
Get all reviews of a snap
#! /usr/bin/env python3
#
# Run this script to get all reviews of a single snap.
#
#%%
from datetime import datetime
import getpass
import hashlib
import json
import requests
# Change this value to see the reviews of a different snap. You can search for the ID of your snap in the list of all
# apps here: https://odrs.gnome.org/1.0/reviews/api/ratings
#
app_id = "io.snapcraft.photoscape-ID8dmjQTxpgM2DB7nty1nj4rzh9SRkby"
#
# example URLs from my snaps:
# app_id = "io.snapcraft.mc-installer-VcdcPCY35DfyUSApgyijx9oes01cIFKX"
# app_id = "io.snapcraft.arduino-q7ex9QXSEs0gfmZHBPYtmSGSwjDTuYhF"
# app_id = "io.snapcraft.krita-r8Shy9i0XE50a3tUlChg3tvjSeLGJ4Za"
# app_id = "io.snapcraft.s4a-61LDltSpWWoJhqH9HPbZvAKBqAee7UuN"
# app_id = "io.snapcraft.mattermost-desktop-ed0pxJoDHrgmAWHH7baX5nryAHy1UNj0"
# app_id = "io.snapcraft.arduino-mhall119-iFmEYkz8yLPeVUj5nkMdGA9xzABOhMsb"
# Generate user_hash using the same algorithm as gnome-software
def get_user_hash():
with open("/etc/machine-id", "r") as mid_f:
machine_id = mid_f.read()
username = getpass.getuser()
salted = "gnome-software[{}:{}]".format(username, machine_id)
return hashlib.sha1(salted.encode()).hexdigest()
body={
"user_hash": get_user_hash(),
"app_id": app_id,
"locale": "en_US",
"distro": "ubuntu",
"version": "2004",
"limit": 200
}
url = "https://odrs.gnome.org/1.0/reviews/api/fetch"
response = requests.post(url, data=json.dumps(body, indent=2).encode())
if not response.ok:
print(f"Call failed with code {response.status_code}")
print(json.dumps(response.json(), indent=2))
exit(1)
reviews = list()
for review in sorted(response.json(), key = lambda i: i['date_created']):
review["rating"] = review["rating"]/20
review["date_created"] = str(datetime.fromtimestamp(review["date_created"]))
reviews.append(review)
print(json.dumps(reviews, indent=2))
print(f"Total reviews: {len(reviews)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment