Ejemplo n.º 1
0
 def update_web(self):
     logger.debug("Updating web %s", self.id)
     gogdata = self.api.web_game_gogdata(self.slug)
     if "gameProductData" in gogdata:
         self.load_web(gogdata["gameProductData"])
     else:
         raise MissingResourceError("{} is missing gameProductData".format(
             self.slug))
Ejemplo n.º 2
0
 def request_json(self, *args, compressed=False, **kwargs):
     resp = self.request(*args, **kwargs)
     if not compressed:
         if DEBUG_JSON:
             logger.debug(resp.text)
         return resp.json()
     else:
         json_comp = resp.content
         json_text = zlib.decompress(json_comp, 15).decode("utf-8")
         if DEBUG_JSON:
             logger.debug(json_text)
         return json.loads(json_text)
Ejemplo n.º 3
0
    def load_web(self, data):
        logger.debug("Loading web data for %s", self.id)
        self.load_web_min(data)

        self.image_background = data["backgroundImageSource"] + ".jpg"
        self.seo_description = data["cardSeoDescription"]
        if data["series"]:
            self.series = Series(self.api, data["series"])
        else:
            self.series = None
        self.required_products = []
        add_products_web(self.api, self.required_products,
                         data["requiredProducts"])
        #self.media IGNORED
        #self.videos IGNORED
        self.dlcs = []
        add_products_web(self.api, self.dlcs, data["dlcs"])
        self.cool_about_it = data["whatsCoolAboutIt"] or None
        if data["screenshots"]:
            self.screenshot_ids = list(data["screenshots"].keys())
        else:
            self.screenshot_ids = None
        self.votes_count = data["votesCount"]
        self.languages_str = data["languages"]
        #self.notification IGNORED
        self.brand_ratings = data["brandRatings"]
        self.children = []
        add_products_web(self.api, self.children, data["children"])
        self.os_requirements = parse_system_reqs(data["osRequirements"])
        self.system_requirements = parse_system_reqs(
            data["systemRequirements"])
        self.recommendations = []
        add_products_web(self.api, self.recommendations,
                         data["recommendations"]["all"])
        # self.bonus_content IGNORED
        self.image_background_bw = data["backgroundImage"]
        self.image_logo_facebook = data["imageLogoFacebook"]
        self.copyrights = data["copyrights"]
        self.reviews = Reviews(self.api, data["reviews"])
        self.reviewable = data["canBeReviewed"]
        self.parents = []
        add_products_web(self.api, self.parents, data["parents"])
        self.extra_requirements = data["extraRequirements"]
        self.packs = []
        add_products_web(self.api, self.packs, data["packs"])
        self.download_size = data["downloadSize"]
        self.genres = parse_genres(self.api, data["genres"])
        self.features = parse_features(self.api, data["features"])
        self.seo_keywords = data["cardSeoKeywords"]
        self.description = data["description"]["full"] or None
        self.description_lead = data["description"]["lead"] or None

        self.loaded.add("web")
Ejemplo n.º 4
0
    def request(self,
                method,
                url,
                authorized=True,
                allow_redirects=False,
                **kwargs):
        # Set headers
        # Prevent getting blocked by default
        headers = {"User-Agent": USER_AGENT}
        # Add a token to the request if it exists
        if self.token is not None:
            if self.token.expired():
                self.token.refresh()
            headers["Authorization"] = "Bearer " + self.token.access_token
        elif authorized:
            raise NotAuthorizedError()

        headers.update(kwargs.pop("headers", {}))

        # Set cookies
        cookies = {}
        if all(self.locale):
            cookies["gog_lc"] = "_".join(self.locale)
        cookies.update(kwargs.pop("cookies", {}))

        # Log request
        if "params" in kwargs:
            full_url = url + "?" + "&".join(
                str(key) + "=" + str(value)
                for key, value in kwargs["params"].items())
            logger.debug("%s %s", method, full_url)
        else:
            logger.debug("%s %s", method, url)

        # Retries
        retries = REQUEST_RETRIES
        while retries > 0:
            resp = requests.request(method,
                                    url,
                                    headers=headers,
                                    cookies=cookies,
                                    **kwargs)
            if resp.status_code < 400:
                return resp
            elif 400 <= resp.status_code < 500:
                break
            else:
                retries -= 1

        resp.raise_for_status()
Ejemplo n.º 5
0
    def load_galaxy(self, data):
        logger.debug("Loading galaxy data for %s", self.id)
        self.title_galaxy = data["title"]
        self.slug = data["slug"]
        self.content_systems = parse_systems(
            data["content_system_compatibility"])

        if data["languages"]:
            self.languages = [
                Language(self.api, name, isocode)
                for isocode, name in data["languages"].items()
            ]
        else:
            self.languages = []
        self.in_development = data["in_development"]["active"]
        self.development_until = maybe_timestamp(
            data["in_development"]["until"])
        self.is_secret = data["is_secret"]
        self.type = data["game_type"]
        self.is_pre_order = data["is_pre_order"]
        self.store_date = maybe_timestamp(data["release_date"])

        self.link_purchase = data["links"]["purchase_link"]
        self.link_card = data["links"]["product_card"]
        self.link_support = data["links"]["support"]
        self.link_forum = data["links"]["forum"]

        self.image_background = data["images"]["background"]
        self.image_logo = data["images"]["logo"]
        self.image_logo_2x = data["images"]["logo2x"]
        self.image_icon = data["images"].get("icon")
        self.image_sidebar_icon = data["images"]["sidebarIcon"]
        self.image_sidebar_icon_2x = data["images"]["sidebarIcon2x"]

        if data.get("dlcs", False):
            self.dlcs = [
                self.api.product(dlc["id"]) for dlc in data["dlcs"]["products"]
            ]
        else:
            self.dlcs = []

        # Expanded

        if "downloads" in data:
            self.installers = [
                Download(self.api, "installers", dl_data)
                for dl_data in data["downloads"]["installers"]
            ]
            self.patches = [
                Download(self.api, "patches", dl_data)
                for dl_data in data["downloads"]["patches"]
            ]
            self.language_packs = [
                Download(self.api, "language_packs", dl_data)
                for dl_data in data["downloads"]["language_packs"]
            ]
            self.bonus_content = [
                Download(self.api, "bonus_content", dl_data)
                for dl_data in data["downloads"]["bonus_content"]
            ]
            self.loaded.add("downloads")

        if "expanded_dlcs" in data:
            self.dlcs = []
            add_products_galaxy(self.api, self.dlcs, data["expanded_dlcs"])
            self.loaded.add("expanded_dlcs")

        if "description" in data:
            self.description = data["description"]["full"]
            self.description_lead = data["description"]["lead"]
            self.cool_about_it = data["description"]["whats_cool_about_it"]
            self.loaded.add("description")

        if "screenshots" in data:
            self.screenshots = data["screenshots"]
            self.loaded.add("screenshots")

        if "videos" in data:
            self.videos = data["videos"]
            self.loaded.add("videos")

        if "related_products" in data:
            self.related_products = []
            add_products_galaxy(self.api, self.related_products,
                                data["related_products"])
            self.loaded.add("related_products")

        if "changelog" in data:
            self.changelog = data["changelog"]
            self.loaded.add("changelog")

        self.loaded.add("galaxy")