2021-08-23 08:22:17 +12:00
|
|
|
import datetime
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
|
|
|
|
2021-08-26 06:25:10 +12:00
|
|
|
class ImageUrlModel:
|
2021-12-24 22:09:50 +13:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
front_tall: str = "",
|
|
|
|
offer_image_tall: str = "",
|
|
|
|
thumbnail: str = "",
|
|
|
|
front_wide: str = "",
|
|
|
|
offer_image_wide: str = "",
|
|
|
|
product_logo: str = "",
|
|
|
|
):
|
2021-06-09 23:08:25 +12:00
|
|
|
self.front_tall = front_tall
|
|
|
|
self.offer_image_tall = offer_image_tall
|
|
|
|
self.thumbnail = thumbnail
|
|
|
|
self.front_wide = front_wide
|
2021-08-26 06:25:10 +12:00
|
|
|
self.offer_image_wide = offer_image_wide
|
2021-09-13 07:19:51 +12:00
|
|
|
self.product_logo = product_logo
|
2021-06-09 23:08:25 +12:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def from_json(cls, json_data: list):
|
|
|
|
tmp = cls()
|
|
|
|
for item in json_data:
|
|
|
|
if item["type"] == "Thumbnail":
|
|
|
|
tmp.thumbnail = item["url"]
|
|
|
|
elif item["type"] == "DieselStoreFrontTall":
|
|
|
|
tmp.front_tall = item["url"]
|
|
|
|
elif item["type"] == "DieselStoreFrontWide":
|
|
|
|
tmp.front_wide = item["url"]
|
|
|
|
elif item["type"] == "OfferImageTall":
|
|
|
|
tmp.offer_image_tall = item["url"]
|
2021-08-26 06:25:10 +12:00
|
|
|
elif item["type"] == "OfferImageWide":
|
|
|
|
tmp.offer_image_wide = item["url"]
|
2021-09-13 07:19:51 +12:00
|
|
|
elif item["type"] == "ProductLogo":
|
|
|
|
tmp.product_logo = item["url"]
|
2021-06-09 23:08:25 +12:00
|
|
|
return tmp
|
|
|
|
|
|
|
|
|
|
|
|
class ShopGame:
|
|
|
|
# TODO: Copyrights etc
|
2021-12-24 22:09:50 +13:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
title: str = "",
|
|
|
|
image_urls: ImageUrlModel = None,
|
|
|
|
social_links: dict = None,
|
|
|
|
langs: list = None,
|
|
|
|
reqs: dict = None,
|
|
|
|
publisher: str = "",
|
|
|
|
developer: str = "",
|
|
|
|
original_price: str = "",
|
|
|
|
discount_price: str = "",
|
|
|
|
tags: list = None,
|
|
|
|
namespace: str = "",
|
|
|
|
offer_id: str = "",
|
|
|
|
):
|
2021-06-09 23:08:25 +12:00
|
|
|
self.title = title
|
|
|
|
self.image_urls = image_urls
|
|
|
|
self.links = []
|
|
|
|
if social_links:
|
|
|
|
for item in social_links:
|
|
|
|
if item.startswith("link"):
|
2021-12-24 22:09:50 +13:00
|
|
|
self.links.append(
|
|
|
|
tuple((item.replace("link", ""), social_links[item]))
|
|
|
|
)
|
2021-06-09 23:08:25 +12:00
|
|
|
else:
|
|
|
|
self.links = []
|
|
|
|
self.languages = langs
|
2021-06-11 05:58:35 +12:00
|
|
|
self.reqs = reqs
|
2021-06-09 23:08:25 +12:00
|
|
|
self.publisher = publisher
|
|
|
|
self.developer = developer
|
|
|
|
self.price = original_price
|
|
|
|
self.discount_price = discount_price
|
2021-06-17 05:03:18 +12:00
|
|
|
self.tags = tags
|
2021-08-23 08:22:17 +12:00
|
|
|
self.namespace = namespace
|
|
|
|
self.offer_id = offer_id
|
2021-06-09 23:08:25 +12:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def from_json(cls, api_data: dict, search_data: dict):
|
|
|
|
if isinstance(api_data, list):
|
|
|
|
for product in api_data:
|
|
|
|
if product["_title"] == "home":
|
|
|
|
api_data = product
|
|
|
|
break
|
2021-06-09 23:25:57 +12:00
|
|
|
if "pages" in api_data.keys():
|
2021-09-06 07:25:57 +12:00
|
|
|
for page in api_data["pages"]:
|
|
|
|
if page["_slug"] == "home":
|
|
|
|
api_data = page
|
|
|
|
break
|
2021-08-23 08:22:17 +12:00
|
|
|
tmp = cls()
|
2021-06-13 10:05:14 +12:00
|
|
|
tmp.title = search_data.get("title", "Fail")
|
2021-08-26 06:25:10 +12:00
|
|
|
tmp.image_urls = ImageUrlModel.from_json(search_data["keyImages"])
|
2021-06-09 23:25:57 +12:00
|
|
|
links = api_data["data"]["socialLinks"]
|
2021-06-09 23:08:25 +12:00
|
|
|
tmp.links = []
|
|
|
|
for item in links:
|
|
|
|
if item.startswith("link"):
|
|
|
|
tmp.links.append(tuple((item.replace("link", ""), links[item])))
|
2021-12-24 22:09:50 +13:00
|
|
|
tmp.available_voice_langs = api_data["data"]["requirements"].get(
|
|
|
|
"languages", "Failed"
|
|
|
|
)
|
2021-06-10 09:12:49 +12:00
|
|
|
tmp.reqs = {}
|
2021-06-17 10:34:23 +12:00
|
|
|
for i, system in enumerate(api_data["data"]["requirements"].get("systems", [])):
|
2021-06-15 08:30:57 +12:00
|
|
|
try:
|
|
|
|
tmp.reqs[system["systemType"]] = {}
|
|
|
|
except KeyError:
|
|
|
|
continue
|
2021-06-09 23:08:25 +12:00
|
|
|
for req in system["details"]:
|
2021-06-11 05:58:35 +12:00
|
|
|
try:
|
2021-12-24 22:09:50 +13:00
|
|
|
tmp.reqs[system["systemType"]][req["title"]] = (
|
|
|
|
req["minimum"],
|
|
|
|
req["recommended"],
|
|
|
|
)
|
2021-06-11 05:58:35 +12:00
|
|
|
except KeyError:
|
|
|
|
pass
|
2021-06-13 10:05:14 +12:00
|
|
|
tmp.publisher = api_data["data"]["meta"].get("publisher", "")
|
|
|
|
tmp.developer = api_data["data"]["meta"].get("developer", "")
|
|
|
|
if not tmp.developer:
|
|
|
|
for i in search_data["customAttributes"]:
|
|
|
|
if i["key"] == "developerName":
|
|
|
|
tmp.developer = i["value"]
|
2021-12-24 22:09:50 +13:00
|
|
|
tmp.price = search_data["price"]["totalPrice"]["fmtPrice"]["originalPrice"]
|
|
|
|
tmp.discount_price = search_data["price"]["totalPrice"]["fmtPrice"][
|
|
|
|
"discountPrice"
|
|
|
|
]
|
|
|
|
tmp.tags = [
|
|
|
|
i.replace("_", " ").capitalize()
|
|
|
|
for i in api_data["data"]["meta"].get("tags", [])
|
|
|
|
]
|
2021-08-23 08:22:17 +12:00
|
|
|
tmp.namespace = search_data["namespace"]
|
|
|
|
tmp.offer_id = search_data["id"]
|
2021-06-09 23:08:25 +12:00
|
|
|
|
|
|
|
return tmp
|
2021-08-23 08:22:17 +12:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class BrowseModel:
|
|
|
|
category: str = "games/edition/base|bundles/games|editors|software/edition/base"
|
|
|
|
count: int = 30
|
2021-09-14 06:24:09 +12:00
|
|
|
language_code: str = "en"
|
|
|
|
country_code: str = "US"
|
2021-08-23 08:22:17 +12:00
|
|
|
keywords: str = ""
|
|
|
|
sortDir: str = "DESC"
|
|
|
|
start: int = 0
|
|
|
|
tag: str = ""
|
|
|
|
withMapping: bool = True
|
|
|
|
withPrice: bool = True
|
2021-12-24 22:09:50 +13:00
|
|
|
date: str = (
|
2022-01-09 11:01:17 +13:00
|
|
|
f"[,{datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%dT%H:%M:%S')}.420Z]"
|
2021-12-24 22:09:50 +13:00
|
|
|
)
|
2021-08-23 08:22:17 +12:00
|
|
|
price: str = ""
|
2021-08-26 08:08:24 +12:00
|
|
|
onSale: bool = False
|
2021-08-23 08:22:17 +12:00
|
|
|
|
|
|
|
@property
|
|
|
|
def __dict__(self):
|
2021-11-22 10:44:45 +13:00
|
|
|
payload = {
|
|
|
|
"allowCountries": self.country_code,
|
|
|
|
"category": self.category,
|
|
|
|
"count": self.count,
|
|
|
|
"country": self.country_code,
|
|
|
|
"keywords": self.keywords,
|
|
|
|
"locale": self.language_code,
|
|
|
|
"priceRange": self.price,
|
|
|
|
"releaseDate": self.date,
|
|
|
|
"sortBy": "releaseDate",
|
|
|
|
"sortDir": self.sortDir,
|
|
|
|
"start": self.start,
|
|
|
|
"tag": self.tag,
|
|
|
|
"withPrice": self.withPrice,
|
|
|
|
}
|
2021-08-23 08:22:17 +12:00
|
|
|
if self.price == "free":
|
|
|
|
payload["freeGame"] = True
|
2021-11-22 10:44:45 +13:00
|
|
|
payload.pop("priceRange")
|
2021-08-23 08:22:17 +12:00
|
|
|
elif self.price.startswith("<price>"):
|
|
|
|
payload["priceRange"] = self.price.replace("<price>", "")
|
2021-08-26 08:08:24 +12:00
|
|
|
if self.onSale:
|
2021-08-23 08:22:17 +12:00
|
|
|
payload["onSale"] = True
|
2021-11-22 10:44:45 +13:00
|
|
|
|
|
|
|
if self.price:
|
|
|
|
payload["effectiveDate"] = self.date
|
|
|
|
else:
|
|
|
|
payload.pop("priceRange")
|
2022-01-09 12:32:37 +13:00
|
|
|
|
2021-08-23 08:22:17 +12:00
|
|
|
return payload
|