mirror of
https://git.wownero.com/wowlet/wowlet-backend.git
synced 2024-08-15 01:03:13 +00:00
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
# SPDX-License-Identifier: BSD-3-Clause
|
|
# Copyright (c) 2022, The Monero Project.
|
|
# Copyright (c) 2022, dsc@xmr.pm
|
|
|
|
from dateutil.parser import parse
|
|
|
|
import settings
|
|
from wowlet_backend.utils import httpget
|
|
from wowlet_backend.tasks import WowletTask
|
|
|
|
|
|
class WownerodTask(WowletTask):
|
|
"""Fetches the latest Wownerod releases using gitea's API"""
|
|
def __init__(self, interval: int = 3600):
|
|
super(WownerodTask, self).__init__(interval)
|
|
|
|
self._cache_key = "wownerod_releases"
|
|
self._cache_expiry = self.interval
|
|
|
|
self._websocket_cmd = "wownerod_releases"
|
|
|
|
self._http_endpoint = "https://git.wownero.com/api/v1/repos/wownero/wownero/releases?limit=1"
|
|
|
|
async def task(self) -> dict:
|
|
blob = await httpget(self._http_endpoint)
|
|
if not isinstance(blob, list) or not blob:
|
|
raise Exception(f"Invalid JSON response for {self._http_endpoint}")
|
|
|
|
blob = blob[0]
|
|
|
|
data = {}
|
|
for asset in blob['assets']:
|
|
operating_system = "linux"
|
|
if "w64" in asset['name'] or "msvc" in asset['name'] or "win64" in asset['name'] or "windows" in asset['name']:
|
|
operating_system = "windows"
|
|
elif "macos" in asset["name"] or "apple" in asset["name"]:
|
|
operating_system = "macos"
|
|
|
|
data.setdefault(operating_system, [])
|
|
data[operating_system].append({
|
|
"name": asset["name"],
|
|
"created_at": parse(asset["created_at"]).strftime("%Y-%m-%d"),
|
|
"url": asset['browser_download_url'],
|
|
"download_count": asset["download_count"],
|
|
"size": asset['size']
|
|
})
|
|
|
|
tag = blob['tag_name']
|
|
if tag.startswith("v"):
|
|
tag = tag[1:]
|
|
|
|
return {
|
|
"version": tag,
|
|
"assets": data
|
|
}
|