20250506.1746536761

This commit is contained in:
fz0x1 2025-05-06 15:06:01 +02:00
parent 1194ba127d
commit 3c5f3155eb
Signed by: fz0x1
GPG key ID: 6F81647BE1B459F4
3 changed files with 77 additions and 17 deletions

View file

@ -62,6 +62,22 @@ class Config:
Config.validate()
def daytime(dt: datetime):
hour = int(dt.strftime("%I"))
am_pm = dt.strftime("%p") # "AM"/"PM"
part_of_day = "none"
if am_pm == "AM":
if 5 <= hour < 12:
part_of_day = "morning"
elif 12 <= hour < 5:
part_of_day = "night"
return part_of_day
def make_logger():
logging.basicConfig(
level=logging.INFO,
@ -104,13 +120,16 @@ def find_closest_entry(data, target_timestamp: int):
)
def convert_diary_date(date_str):
def convert_diary_date(date_str, to_str: bool = True):
try:
return (
dt = (
datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%SZ")
.replace(tzinfo=ZoneInfo("UTC"))
.astimezone(TZ)
).strftime("%d %b %Y at %H:%M:%S:")
)
if to_str:
return dt.strftime("%d %b %Y at %H:%M:%S:")
return dt
except ValueError:
return None
@ -569,9 +588,15 @@ def export():
)
try:
diary_datetime = convert_diary_date(create_time)
daytime_tag = daytime(convert_diary_date(create_time, False))
if daytime_tag != "none":
content += f"\n@{daytime_tag}"
content = shlex.quote(content)
subprocess.run(
f'printf "%s %b" "{convert_diary_date(create_time)}" {content} | jrnl {diary_name}',
f'printf "%s %b" "{diary_datetime}" {content} | jrnl {diary_name}',
shell=True,
capture_output=True,
text=True,
@ -629,13 +654,24 @@ def insert():
"""
Inserting a string from the terminal
"""
content = shlex.quote(sys.argv[4])
diary_datetime = convert_diary_date(datenow_timestamp)
daytime_tag = daytime(convert_diary_date(datenow_timestamp, False))
content = sys.argv[4]
# inserting daytime tag
if daytime_tag != "none":
content += f"\n@{daytime_tag}"
content = shlex.quote(content)
if not content:
print("There is no text")
sys.exit(1)
try:
subprocess.run(
f'printf "%s %s" "{convert_diary_date(datenow_timestamp)}" {content} | jrnl {diary_name}',
f'printf "%s %s" "{diary_datetime}" {content} | jrnl {diary_name}',
shell=True,
capture_output=True,
text=True,
@ -658,11 +694,21 @@ def insert():
subprocess.run(["nvim", temp_file_path], text=True, check=True)
with open(temp_file_path, "r") as file:
diary_datetime = convert_diary_date(datenow_timestamp)
daytime_tag = daytime(diary_datetime)
content = file.read()
# inserting daytime tag
if daytime_tag != "none":
content += f"\n@{daytime_tag}"
content = shlex.quote(file.read())
if hash != make_hash(temp_file_path):
try:
subprocess.run(
f'printf "%s %s" "{convert_diary_date(datenow_timestamp)}" {content} | jrnl {diary_name}',
f'printf "%s %s" "{diary_datetime}" {content} | jrnl {diary_name}',
shell=True,
capture_output=True,
text=True,