2022-11-06 07:05:50 +00:00
|
|
|
import re
|
2022-10-22 15:26:07 +00:00
|
|
|
from datetime import datetime
|
2022-03-19 17:44:35 +00:00
|
|
|
from typing import List
|
2022-10-22 15:26:07 +00:00
|
|
|
from defs.format_time import strf_time, strp_time
|
2022-03-19 17:44:35 +00:00
|
|
|
|
2022-11-06 07:05:50 +00:00
|
|
|
REMOVE_HTML = re.compile(r"<[^>]+>", re.S)
|
|
|
|
|
2022-03-19 17:44:35 +00:00
|
|
|
|
|
|
|
class Assets:
|
|
|
|
def __init__(self, data: dict):
|
|
|
|
self.name = data["name"]
|
|
|
|
self.url = data["downloadUrl"]
|
|
|
|
|
|
|
|
|
|
|
|
class Release:
|
|
|
|
def __init__(self, data: dict):
|
|
|
|
self.name: str = data["name"]
|
|
|
|
self.url: str = data["url"]
|
2022-11-06 07:05:50 +00:00
|
|
|
self.descriptionHTML: str = data.get("descriptionHTML", "")
|
|
|
|
self.description = REMOVE_HTML.sub("", self.descriptionHTML).strip()
|
2022-03-19 17:44:35 +00:00
|
|
|
self.publishedAt: str = strf_time(data["publishedAt"])
|
2022-10-22 15:26:07 +00:00
|
|
|
self.publishedAtTime: datetime = strp_time(data["publishedAt"])
|
2022-03-19 17:44:35 +00:00
|
|
|
self.tagName: str = data["tagName"]
|
|
|
|
self.isPrerelease: bool = data["isPrerelease"]
|
|
|
|
assets = []
|
|
|
|
if data["releaseAssets"]:
|
2022-08-08 06:38:00 +00:00
|
|
|
assets.extend(Assets(i) for i in data["releaseAssets"])
|
2022-03-19 17:44:35 +00:00
|
|
|
self.releaseAssets: List[Assets] = assets
|
|
|
|
self.releaseAssetsLen = len(assets)
|
|
|
|
|
|
|
|
|
|
|
|
class Module:
|
|
|
|
def __init__(self, data: dict):
|
|
|
|
self.name: str = data["name"]
|
2022-08-08 06:38:00 +00:00
|
|
|
self.description: str = data["description"] or ""
|
|
|
|
self.url: str = data["url"] or ""
|
|
|
|
self.homepageUrl: str = data["homepageUrl"] or data["url"]
|
|
|
|
|
|
|
|
self.sourceUrl: str = data["sourceUrl"] or ""
|
2022-03-19 17:44:35 +00:00
|
|
|
self.hide: bool = data["hide"]
|
|
|
|
self.createdAt: str = strf_time(data["createdAt"])
|
|
|
|
text = []
|
|
|
|
for i in data["collaborators"]:
|
2023-02-03 10:05:44 +00:00
|
|
|
if i.get("name"):
|
|
|
|
text.append(i["name"].replace(" ", "_").replace(".", "_").replace("-", "_"))
|
2022-03-19 17:44:35 +00:00
|
|
|
else:
|
2023-02-03 10:05:44 +00:00
|
|
|
text.append(i["login"].replace(" ", "_").replace(".", "_").replace("-", "_"))
|
2022-03-19 17:44:35 +00:00
|
|
|
self.collaborators: List[str] = text
|
2022-10-22 16:03:33 +00:00
|
|
|
self.latestRelease: str = data.get("latestRelease", "")
|
2022-03-19 17:44:35 +00:00
|
|
|
releases = []
|
|
|
|
if data["releases"]:
|
2022-08-08 06:38:00 +00:00
|
|
|
releases.extend(Release(i) for i in data["releases"])
|
2022-10-22 15:26:07 +00:00
|
|
|
if data.get("betaReleases"):
|
|
|
|
releases.extend(Release(i) for i in data["betaReleases"])
|
|
|
|
releases.sort(key=lambda x: x.publishedAtTime, reverse=True)
|
2022-03-19 17:44:35 +00:00
|
|
|
self.releases: List[Release] = releases
|
2022-03-20 10:04:30 +00:00
|
|
|
self.updatedAt: str = releases[0].publishedAt if releases else strf_time(data["updatedAt"])
|
2022-08-08 06:38:00 +00:00
|
|
|
self.summary: str = data["summary"] or ""
|
|
|
|
self.scope: List[str] = data["scope"] or []
|
2022-03-19 17:44:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TrackMessage:
|
|
|
|
def __init__(self, text, url, name, button):
|
|
|
|
self.text = text
|
|
|
|
self.url = url
|
|
|
|
self.name = name
|
|
|
|
self.button = button
|