def load_token(self): """Load token from disk""" if not os.path.exists(self.token_path): raise AuthenticationError("No GOG token available") with open(self.token_path) as token_file: token_content = json.loads(token_file.read()) return token_content
def make_request(self, url): """Send a cookie authenticated HTTP request to GOG""" request = Request(url, cookies=self.load_cookies()) request.get() if request.content.startswith(b"<"): raise AuthenticationError("Token expired, please log in again") return request.json
def get_products_page(self, page=1, search=None): """Return a single page of games""" if not self.is_authenticated(): raise AuthenticationError("User is not logged in") params = {"mediaType": "1"} if page: params["page"] = page if search: params["search"] = search url = self.embed_url + "/account/getFilteredProducts?" + urlencode(params) return self.make_request(url)