mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-03 17:39:42 +02:00
add (almost) final download log logic
This commit is contained in:
@@ -6,7 +6,7 @@ from typing import List
|
|||||||
class Download:
|
class Download:
|
||||||
title: str
|
title: str
|
||||||
url: str
|
url: str
|
||||||
torrent_uri: str
|
magnet_uri: str
|
||||||
completed: bool
|
completed: bool
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
@@ -1,16 +1,32 @@
|
|||||||
from core.utils.data.models import Download, DownloadList
|
from core.utils.data.models import Download, DownloadList
|
||||||
|
from core.utils.data.state import state
|
||||||
|
from dataclasses import asdict
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def add_download_log(title, url, magnet_uri, completed) -> DownloadList:
|
def add_download_log(title, url, magnet_uri, completed) -> DownloadList:
|
||||||
downloads: list[Download] = []
|
downloads_file = os.path.join(state.settings_path, "downloads.json")
|
||||||
|
|
||||||
|
if os.path.exists(downloads_file) and os.path.getsize(downloads_file) > 0:
|
||||||
|
try:
|
||||||
|
with open(downloads_file, "r") as file:
|
||||||
|
existing_data = json.load(file)
|
||||||
|
downloads = [Download(**d) for d in existing_data.get("data", [])]
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
downloads = []
|
||||||
|
else:
|
||||||
|
downloads = []
|
||||||
|
|
||||||
downloads.append(Download(
|
downloads.append(Download(
|
||||||
title=title,
|
title=title,
|
||||||
url=url,
|
url=url,
|
||||||
magnet_uri=magnet_uri,
|
magnet_uri=magnet_uri,
|
||||||
completed=completed
|
completed=completed
|
||||||
))
|
))
|
||||||
|
|
||||||
return DownloadList(data=downloads, count=len(downloads))
|
download_list = DownloadList(data=downloads, count=len(downloads))
|
||||||
|
with open(downloads_file, "w") as file:
|
||||||
|
json.dump(asdict(download_list), file, indent=4)
|
||||||
|
|
||||||
|
return download_list
|
||||||
Reference in New Issue
Block a user