Support chinese variant, QQ object in launcher and some code optimizations

This commit is contained in:
2022-02-16 00:49:33 +07:00
parent 048a7ac9d0
commit c22918673b
19 changed files with 389 additions and 58 deletions

View File

@ -3,7 +3,7 @@ class Background:
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.
`url` and `icon` variables are not 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
@ -16,8 +16,9 @@ class Background:
- :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.
- :class:`dict` raw: The launcher background raw information.
"""
def __init__(self, background, icon, url, version, bg_checksum, raw):
"""Inits the launcher background class"""
self.background = background
@ -31,4 +32,4 @@ class Background:
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)
data["version"], data["bg_checksum"], data)

View File

@ -16,9 +16,10 @@ class IconButton:
- :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.
- :class:`list[LauncherIconOtherLink]` other_links: Other links in the button.
- :class:`dict` raw: The launcher background raw information.
"""
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
@ -38,5 +39,4 @@ class IconButton:
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)
data["qr_desc"], data["img_hover"], other_links, data)

View File

@ -1,16 +1,33 @@
from worthless.classes.launcher import background, banner, iconbutton, post
from worthless.classes.launcher import background, banner, iconbutton, post, qq
Background = background.Background
Banner = banner.Banner
IconButton = iconbutton.IconButton
Post = post.Post
QQ = qq.QQ
class Info:
def __init__(self, lc_background: Background, lc_banner: list[Banner], icon: list[IconButton], lc_post: list[Post]):
"""Contains the launcher information
Note that QQ is not wrapped due to not having access to the chinese yuanshen launcher.
You can contribute to the project if you want :D
Attributes:
- :class:`worthless.classes.launcher.background.Background` background: The launcher background information.
- :class:`worthless.classes.launcher.banner.Banner` banner: The launcher banner information.
- :class:`worthless.classes.launcher.iconbutton.IconButton` icon: The launcher icon buttons information.
- :class:`worthless.classes.launcher.qq.QQ` post: The launcher QQ posts information.
- :class:`dict` raw: The launcher raw information.
"""
def __init__(self, lc_background: Background, lc_banner: list[Banner], icon: list[IconButton], lc_post: list[Post],
lc_qq: list[QQ], raw: dict):
self.background = lc_background
self.banner = lc_banner
self.icon = icon
self.post = lc_post
self.qq = lc_qq
self.raw = raw
@staticmethod
def from_dict(data):
@ -24,5 +41,8 @@ class Info:
lc_post = []
for p in data["post"]:
lc_post.append(Post.from_dict(p))
return Info(bg, lc_banner, lc_icon, lc_post)
lc_qq = []
for q in data["qq"]:
lc_qq.append(QQ.from_dict(q))
return Info(bg, lc_banner, lc_icon, lc_post, lc_qq, data)

View File

@ -13,13 +13,13 @@ class Post:
Attributes:
- :class:`str` post_id: The launcher post id.
- :class:`str` type: The post type, as explained above.
- :class:`str` type: The post type, can be POST_TYPE_ANNOUNCE, POST_TYPE_ACTIVITY and POST_TYPE_INFO
- :class:`str` tittle: The post title.
- :class:`str` url: The post target url.
- :class:`str` show_time: The time when the post will be shown.
- :class:`str` order: The post order.
- :class:`str` title: The post title.
- :class:`dict` raw: The banner raw information.
- :class:`dict` raw: The post raw information.
"""
def __init__(self, post_id, post_type, tittle, url, show_time, order, title, raw):
self.post_id = post_id

View File

@ -0,0 +1,35 @@
class QQ:
"""Contains the launcher QQ information
Note that QQ is not wrapped due to not having access to the chinese yuanshen launcher.
You can contribute to the project if you want :D
Attributes:
- :class:`str` qq_id: The id of the QQ post
- :class:`str` name: The name of the QQ post
- :class:`int` number: The number of the QQ post
- :class:`str` code: The QQ post url.
- :class:`dict` raw: The launcher raw information.
"""
def __init__(self, qq_id, name, number, code, raw):
self.qq_id = qq_id
self.name = name
self.number = number
self.code = code
self.raw = raw
@staticmethod
def from_dict(raw: dict) -> 'QQ':
"""Creates a QQ object from a dictionary
Args:
raw (dict): The raw dictionary
Returns:
QQ: The QQ object
"""
qq_id = raw.get('qq_id')
name = raw.get('name')
number = int(raw.get('number'))
code = raw.get('code')
return QQ(qq_id, name, number, code, raw)