From a7ddd0c49a812ab8eb3ee56a84331190555c7c81 Mon Sep 17 00:00:00 2001 From: tretrauit Date: Sat, 29 Jan 2022 23:25:03 +0700 Subject: [PATCH] Object-oriented programming All launcher functions are now return an object instead of a dict --- _trial_temp.lock | 1 + .../_trial_temp => _trial_temp}/_trial_marker | 0 requirements.txt | 1 + worthless/classes/__init__.py | 0 worthless/classes/launcher/__init__.py | 0 worthless/classes/launcher/background.py | 34 +++++++++++++++ worthless/classes/launcher/banner.py | 29 +++++++++++++ worthless/classes/launcher/iconbutton.py | 42 +++++++++++++++++++ worthless/classes/launcher/iconotherlink.py | 9 ++++ worthless/classes/launcher/info.py | 3 ++ worthless/classes/launcher/post.py | 29 +++++++++++++ worthless/patcher.py | 0 worthless/requirements.txt | 1 + 13 files changed, 149 insertions(+) create mode 120000 _trial_temp.lock rename {tests/_trial_temp => _trial_temp}/_trial_marker (100%) create mode 100644 requirements.txt create mode 100644 worthless/classes/__init__.py create mode 100644 worthless/classes/launcher/__init__.py create mode 100644 worthless/classes/launcher/background.py create mode 100644 worthless/classes/launcher/banner.py create mode 100644 worthless/classes/launcher/iconbutton.py create mode 100644 worthless/classes/launcher/iconotherlink.py create mode 100644 worthless/classes/launcher/info.py create mode 100644 worthless/classes/launcher/post.py create mode 100644 worthless/patcher.py create mode 100644 worthless/requirements.txt diff --git a/_trial_temp.lock b/_trial_temp.lock new file mode 120000 index 0000000..2a1f712 --- /dev/null +++ b/_trial_temp.lock @@ -0,0 +1 @@ +15389 \ No newline at end of file diff --git a/tests/_trial_temp/_trial_marker b/_trial_temp/_trial_marker similarity index 100% rename from tests/_trial_temp/_trial_marker rename to _trial_temp/_trial_marker diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7c05f0b --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +aiohttp==3.8.1 diff --git a/worthless/classes/__init__.py b/worthless/classes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/worthless/classes/launcher/__init__.py b/worthless/classes/launcher/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/worthless/classes/launcher/background.py b/worthless/classes/launcher/background.py new file mode 100644 index 0000000..809e124 --- /dev/null +++ b/worthless/classes/launcher/background.py @@ -0,0 +1,34 @@ +class Background: + """Contains the launcher background information + + Note that the `background` variable is an url to the background image, + while the `url` variable contains an empty string, so it seems that the + `url` and `icon` variables are used by the official launcher itself. + + Also, the launcher background checksum is using an algorithm which I + haven't found out yet, so you better not rely on it but instead rely + on the url name which contains a md5 sum in the first part of the name. + + Attributes: + + - :class:`str` background: The launcher background url. + - :class:`str` icon: The icon url. + - :class:`str` url: The url variable. + - :class:`str` version: The launcher background version. + - :class:`str` bg_checksum: The launcher background checksum. + - :class:`dict` raw: The launcher background raw information in dict. + """ + def __init__(self, background, icon, url, version, bg_checksum, raw): + """Inits the launcher background class""" + self.background = background + self.icon = icon + self.url = url + self.version = version + self.bg_checksum = bg_checksum + self.raw = raw + + @staticmethod + def from_dict(data) -> 'Background': + """Creates a launcher background from a dictionary.""" + return Background(data["background"], data["icon"], data["url"], + data["version"], data["bg_checksum"], data) diff --git a/worthless/classes/launcher/banner.py b/worthless/classes/launcher/banner.py new file mode 100644 index 0000000..037eab5 --- /dev/null +++ b/worthless/classes/launcher/banner.py @@ -0,0 +1,29 @@ +class Banner: + """Contains a launcher banner information + + Note that the banner name is in chinese, so you may not find this variable useful. + Also, the banner has a variable called `order`, you can use that to sort the banner + like the official launcher does. + + Attributes: + + - :class:`str` banner_id: The launcher banner id. + - :class:`str` name: The banner name. + - :class:`str` img: The banner image url. + - :class:`str` url: The banner target url. + - :class:`str` order: The banner order. + - :class:`str` name: The banner name. + - :class:`dict` raw: The banner raw information. + """ + def __init__(self, banner_id, name, img, url, order, raw): + self.banner_id = banner_id + self.name = name + self.img = img + self.url = url + self.order = order + self.raw = raw + + @staticmethod + def from_dict(data) -> 'Banner': + """Creates a launcher banner from a dictionary.""" + return Banner(data["banner_id"], data["name"], data["img"], data["url"], data["order"], data) diff --git a/worthless/classes/launcher/iconbutton.py b/worthless/classes/launcher/iconbutton.py new file mode 100644 index 0000000..a29ecb8 --- /dev/null +++ b/worthless/classes/launcher/iconbutton.py @@ -0,0 +1,42 @@ +from worthless.classes.launcher.launchericonotherlink import IconOtherLink + + +class IconButton: + """Contains a launcher icon button information + + The `qr_img`, `qr_desc` variables are not used in the official launcher + (since it's empty) + + Attributes: + + - :class:`str` icon_id: The icon id. + - :class:`str` img: The icon url. + - :class:`str` tittle: The icon title. + - :class:`str` url: The icon target url. + - :class:`str` qr_img: The QR code url. + - :class:`str` qr_desc: The QR code description. + - :class:`str` img_hover: The icon url when hovered over. + - :class:`dict[LauncherIconOtherLink]` other_links: Other links in the button. + - :class:`dict` raw: The launcher background raw information in dict. + """ + def __init__(self, icon_id, img, tittle, url, qr_img, qr_desc, img_hover, other_links, raw): + """Inits the launcher icon class""" + self.icon_id = icon_id + self.img = img + self.tittle = tittle + self.url = url + self.qr_img = qr_img + self.qr_desc = qr_desc + self.img_hover = img_hover + self.other_links = other_links + self.raw = raw + + @staticmethod + def from_dict(data) -> 'IconButton': + """Creates a launcher background from a dictionary.""" + other_links = [] + for link in data['other_links']: + other_links.append(IconOtherLink.from_dict(link)) + return IconButton(data["icon_id"], data["img"], data["tittle"], data["url"], data["qr_img"], + data["qr_desc"], data["img_hover"], other_links, data) + diff --git a/worthless/classes/launcher/iconotherlink.py b/worthless/classes/launcher/iconotherlink.py new file mode 100644 index 0000000..b462dab --- /dev/null +++ b/worthless/classes/launcher/iconotherlink.py @@ -0,0 +1,9 @@ +class IconOtherLink: + def __init__(self, title, url): + self.title = title + self.url = url + + @staticmethod + def from_dict(data) -> 'IconOtherLink': + """Creates a launcher icon other link from a dictionary.""" + return IconOtherLink(data["title"], data["url"]) diff --git a/worthless/classes/launcher/info.py b/worthless/classes/launcher/info.py new file mode 100644 index 0000000..f2f3022 --- /dev/null +++ b/worthless/classes/launcher/info.py @@ -0,0 +1,3 @@ +class LauncherInfo: + def __init__(self): + pass diff --git a/worthless/classes/launcher/post.py b/worthless/classes/launcher/post.py new file mode 100644 index 0000000..037eab5 --- /dev/null +++ b/worthless/classes/launcher/post.py @@ -0,0 +1,29 @@ +class Banner: + """Contains a launcher banner information + + Note that the banner name is in chinese, so you may not find this variable useful. + Also, the banner has a variable called `order`, you can use that to sort the banner + like the official launcher does. + + Attributes: + + - :class:`str` banner_id: The launcher banner id. + - :class:`str` name: The banner name. + - :class:`str` img: The banner image url. + - :class:`str` url: The banner target url. + - :class:`str` order: The banner order. + - :class:`str` name: The banner name. + - :class:`dict` raw: The banner raw information. + """ + def __init__(self, banner_id, name, img, url, order, raw): + self.banner_id = banner_id + self.name = name + self.img = img + self.url = url + self.order = order + self.raw = raw + + @staticmethod + def from_dict(data) -> 'Banner': + """Creates a launcher banner from a dictionary.""" + return Banner(data["banner_id"], data["name"], data["img"], data["url"], data["order"], data) diff --git a/worthless/patcher.py b/worthless/patcher.py new file mode 100644 index 0000000..e69de29 diff --git a/worthless/requirements.txt b/worthless/requirements.txt new file mode 100644 index 0000000..7c05f0b --- /dev/null +++ b/worthless/requirements.txt @@ -0,0 +1 @@ +aiohttp==3.8.1