Skip to content

Commit

Permalink
More work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
razzeee committed Oct 12, 2024
1 parent 6e39838 commit 054b99a
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions backend/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,34 +395,50 @@ def appstream2dict(appstream_url=None) -> dict[str, dict]:
app["id"] = appid
apps[appid] = app

if "content_rating" in app:
print(get_content_rating_details(app["content_rating"], "de_DE"))

return apps


def get_content_rating_details(content_rating: dict, locale: str) -> dict:
if content_rating is None or content_rating.get("type") is None:
return {}
system = AppStream.ContentRatingSystem.from_locale(locale)
rating = AppStream.ContentRating()
rating.set_kind(content_rating["kind"])
details = {"attrs": []}

rating.set_kind(content_rating["type"])
contentRatingResult = {}

for attr, level in content_rating.items():
if attr == 'kind':
if attr == "type" or level is None:
continue
c_level = AppStream.ContentRatingValue.from_string(level)
rating.add_attribute(attr, c_level)
description = AppStream.ContentRating.attribute_get_description(attr, c_level)
details["attrs"] = {
"attr": attr,
contentRatingResult["details"] = {
"id": attr,
"level": level,
"description": description,
}

min_age = AppStream.ContentRating.get_minimum_age(rating)
# Maxint is used for no details available
if min_age == MAXUINT:
details["minimumAge"] = None
contentRatingResult["minimumAge"] = None
contentRatingResult["contentRatingSystem"] = (
AppStream.ContentRatingSystem.to_string(system)
)
else:
details["minimumAge"] = AppStream.ContentRatingSystem.format_age(system, min_age)
contentRatingResult["minimumAge"] = AppStream.ContentRatingSystem.format_age(
system, min_age
)
contentRatingResult["contentRatingSystem"] = (
AppStream.ContentRatingSystem.to_string(system)
)

return details
print("details", contentRatingResult)
return contentRatingResult


def get_clean_app_id(app_id: str):
Expand Down

0 comments on commit 054b99a

Please sign in to comment.