Dodanie skryptu konwertera, przygotowanie do kategoryzacji list i dodanie pliku źródłowego JSON #1

Merged
wiktor merged 7 commits from converter into master 2025-05-20 18:09:48 +02:00
Showing only changes of commit e28100335d - Show all commits

View File

@ -72,17 +72,17 @@ class UnsupportedTargetFormatError(Exception):
pass
def convert(data: dict, target_format: str) -> str:
def convert(data: dict, last_modified: datetime, target_format: str) -> str:
match target_format:
case "adguard":
return adguard_conversion(data)
return adguard_conversion(last_modified, data)
case _:
raise UnsupportedTargetFormatError
def adguard_conversion(data: dict) -> list[str]:
def adguard_conversion(last_modified: datetime, data: dict) -> list[str]:
header_lines: list[str] = [
f"! Blocking list automatically generated at {datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S %Z%z')}",
f"! Blocking list automatically generated at {last_modified.strftime('%Y-%m-%d %H:%M:%S %Z%z')}",
wiktor marked this conversation as resolved Outdated
Outdated
Review

tutaj zamiast obecnej daty użyjmy mtime źródłowego pliku JSON. Wtedy buildy będą bardziej deterministyczne

tutaj zamiast obecnej daty użyjmy `mtime` źródłowego pliku JSON. Wtedy buildy będą bardziej deterministyczne

masz na myśli pobieranie datetime ostatniej modyfikacji pliku źródłowego JSON?

masz na myśli pobieranie datetime ostatniej modyfikacji pliku źródłowego JSON?
Outdated
Review

dokładnie tak!

dokładnie tak!
"! Created with ❤️ by internet-czas-dzialac.pl",
]
@ -107,6 +107,11 @@ def dump_output(data: str, output_file: str) -> None:
file.write(data)
def get_last_modified_datetime(file_path: str) -> datetime:
timestamp: float = os.path.getmtime(file_path)
return datetime.fromtimestamp(timestamp, tz=timezone.utc)
def main() -> None:
# Start measuring time
start_time: float = perf_counter()
@ -117,6 +122,7 @@ def main() -> None:
# Load data
try:
data: dict = load_data(args.inputfile)
last_modified: datetime = get_last_modified_datetime(args.inputfile)
except FileNotFoundError:
logger.error(f"File {args.inputfile} not found!")
return
@ -129,7 +135,7 @@ def main() -> None:
# Convert
try:
output = convert(data, args.targetformat)
output = convert(data, last_modified, args.targetformat)
except UnsupportedTargetFormatError:
logger.error('Unsupported format. For now only "adguard" is supported.')
return