Dump app obj

This commit is contained in:
Nikhil Badyal
2024-04-14 23:59:29 +05:30
parent 410a3baded
commit d5c4301fce
2 changed files with 13 additions and 5 deletions
+6 -2
View File
@@ -5,7 +5,7 @@ import hashlib
import pathlib
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from typing import Self
from typing import Any, Self
from loguru import logger
from pytz import timezone
@@ -90,6 +90,10 @@ class APP(object):
attrs = vars(self)
return ", ".join([f"{key}: {value}" for key, value in attrs.items()])
def for_dump(self: Self) -> dict[str, Any]:
"""Convert the instance of this class to json."""
return self.__dict__
@staticmethod
def download(url: str, config: RevancedConfig, assets_filter: str, file_name: str = "") -> tuple[str, str]:
"""The `download` function downloads a file from a given URL & filters the assets based on a given filter.
@@ -113,7 +117,7 @@ class APP(object):
Returns
-------
a string, which is the file name of the downloaded file.
tuple of strings, which is the tag,file name of the downloaded file.
"""
from src.downloader.download import Downloader
+7 -3
View File
@@ -9,13 +9,16 @@ import time
from datetime import datetime
from json import JSONDecodeError
from pathlib import Path
from typing import Any
from typing import TYPE_CHECKING, Any
import requests
from loguru import logger
from pytz import timezone
from requests import Response, Session
if TYPE_CHECKING:
from src.app import APP
from src.downloader.sources import APK_MIRROR_APK_CHECK
from src.downloader.utils import status_code_200
from src.exceptions import ScrapingError
@@ -227,7 +230,7 @@ def datetime_to_ms_epoch(dt: datetime) -> int:
return int(round(microseconds / float(1000)))
def save_patch_info(app: Any) -> None:
def save_patch_info(app: "APP") -> None:
"""Save version info a patching resources used to a file."""
try:
with Path(updates_file).open() as file:
@@ -237,12 +240,13 @@ def save_patch_info(app: Any) -> None:
old_version = {} # or any default value you want to assign
old_version[app.app_name] = {
"version": app.app_version,
"app_version": app.app_version,
"integrations_version": app.resource["integrations"]["version"],
"patches_version": app.resource["patches"]["version"],
"cli_version": app.resource["cli"]["version"],
"patches_json_version": app.resource["patches_json"]["version"],
"ms_epoch_since_patched": datetime_to_ms_epoch(datetime.now(timezone(time_zone))),
"date_patched": datetime.now(timezone(time_zone)),
"app_dump": app.for_dump(),
}
Path(updates_file).write_text(json.dumps(old_version, indent=4, default=str) + "\n")