fix: date was updating at each edit
All checks were successful
ci/woodpecker/push/publish Pipeline was successful

This commit is contained in:
Mylloon 2023-12-22 15:25:47 +01:00
parent b9b762d793
commit 1c8c1ba9f3
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -1,4 +1,4 @@
from os import listdir
from os import listdir, utime
from os import path as os_path
from os import remove as os_remove
from time import ctime
@ -45,7 +45,7 @@ def get_post(filename: str) -> File | None:
return None
else:
with open(filename, "r") as reader:
return File(reader.read(), ctime(os_path.getctime(filename)))
return File(reader.read(), ctime(os_path.getmtime(filename)))
def delete_post(filename: str) -> bool:
@ -73,12 +73,11 @@ def fresh_file_id() -> int:
return filename
def exist_post(file_id: int) -> bool:
def exist_post(file_id: int) -> float | None:
try:
open(post_filename(file_id))
return True
return os_path.getmtime(post_filename(file_id))
except FileNotFoundError:
return False
return None
def create_post(file_id: int, content: str) -> bool:
@ -86,8 +85,14 @@ def create_post(file_id: int, content: str) -> bool:
# check if the file already exists
update = exist_post(file_id)
filename = post_filename(file_id)
# write into the file
with open(post_filename(file_id), "w", encoding="utf-8") as f:
with open(filename, "w", encoding="utf-8") as f:
f.write(content)
return update
# keep metadata
if update:
utime(filename, (update, update))
return True
return False