Zmiana datetime.now na path.getmtime dla komentarza
This commit is contained in:
parent
feae847950
commit
e28100335d
@ -72,17 +72,17 @@ class UnsupportedTargetFormatError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def convert(data: dict, target_format: str) -> str:
|
def convert(data: dict, last_modified: datetime, target_format: str) -> str:
|
||||||
match target_format:
|
match target_format:
|
||||||
case "adguard":
|
case "adguard":
|
||||||
return adguard_conversion(data)
|
return adguard_conversion(last_modified, data)
|
||||||
case _:
|
case _:
|
||||||
raise UnsupportedTargetFormatError
|
raise UnsupportedTargetFormatError
|
||||||
|
|
||||||
|
|
||||||
def adguard_conversion(data: dict) -> list[str]:
|
def adguard_conversion(last_modified: datetime, data: dict) -> list[str]:
|
||||||
header_lines: 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')}",
|
||||||
"! Created with ❤️ by internet-czas-dzialac.pl",
|
"! Created with ❤️ by internet-czas-dzialac.pl",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -107,6 +107,11 @@ def dump_output(data: str, output_file: str) -> None:
|
|||||||
file.write(data)
|
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:
|
def main() -> None:
|
||||||
# Start measuring time
|
# Start measuring time
|
||||||
start_time: float = perf_counter()
|
start_time: float = perf_counter()
|
||||||
@ -117,6 +122,7 @@ def main() -> None:
|
|||||||
# Load data
|
# Load data
|
||||||
try:
|
try:
|
||||||
data: dict = load_data(args.inputfile)
|
data: dict = load_data(args.inputfile)
|
||||||
|
last_modified: datetime = get_last_modified_datetime(args.inputfile)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logger.error(f"File {args.inputfile} not found!")
|
logger.error(f"File {args.inputfile} not found!")
|
||||||
return
|
return
|
||||||
@ -129,7 +135,7 @@ def main() -> None:
|
|||||||
|
|
||||||
# Convert
|
# Convert
|
||||||
try:
|
try:
|
||||||
output = convert(data, args.targetformat)
|
output = convert(data, last_modified, args.targetformat)
|
||||||
except UnsupportedTargetFormatError:
|
except UnsupportedTargetFormatError:
|
||||||
logger.error('Unsupported format. For now only "adguard" is supported.')
|
logger.error('Unsupported format. For now only "adguard" is supported.')
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user