formated code and added delta hours

This commit is contained in:
Alexander Nigl 2025-04-06 17:40:58 +02:00
parent 549a71a99b
commit 051f04f7b2
2 changed files with 37 additions and 20 deletions

View File

@ -1,14 +1,14 @@
from setuptools import setup, find_packages
from setuptools import setup
setup(
name="timer",
version="0.1",
version="0.2",
author="Alexander Nigl",
py_modules=["timer"],
install_requires=[
"click",
"click",
],
entry_points = {
'console_scripts': ['timer=timer:main'],
}
entry_points={
"console_scripts": ["timer=timer:main"],
},
)

View File

@ -4,30 +4,47 @@ from tkinter import Tk, CENTER, Label
import click
import typing as t
DELTASECONDS = "+%Ss"
DELTAMINUTES = "+%Mm"
DELTAHOURS = "+%Hh"
HOURS = "%H:%M"
DATETIME_FORMAT = [
"%Y-%m-%d",
"%Y-%m-%dT%H:%M:%S",
"%Y-%m-%d %H:%M:%S",
"%Y-%m-%d %H:%M",
HOURS,
DELTAHOURS,
DELTAMINUTES,
DELTASECONDS,
]
class DateTime(click.DateTime):
def _try_to_convert_date(self, value: t.Any, format: str) -> t.Optional[datetime]:
try:
if format == SECONDS and value[-1] == "s":
return datetime.datetime.now() + datetime.timedelta(seconds=int(value[1:-1]))
if format == MINUTES and value[-1] == "m":
return datetime.datetime.now() + datetime.timedelta(minutes=int(value[1:-1]))
if format == DELTASECONDS and value[-1] == "s":
return datetime.datetime.now() + datetime.timedelta(
seconds=int(value[1:-1])
)
if format == DELTAMINUTES and value[-1] == "m":
return datetime.datetime.now() + datetime.timedelta(
minutes=int(value[1:-1])
)
if format == DELTAHOURS and value[-1] == "h":
return datetime.datetime.now() + datetime.timedelta(
hours=int(value[1:-1])
)
if format == HOURS:
return datetime.datetime.combine(
datetime.datetime.now().date(),
datetime.datetime.strptime(value, format).time()
datetime.datetime.strptime(value, format).time(),
)
return datetime.datetime.strptime(value, format)
except ValueError:
return None
SECONDS = '+%Ms'
MINUTES = '+%Mm'
HOURS = '%H:%M'
DATETIME_FORMAT = ['%Y-%m-%d', '%Y-%m-%dT%H:%M:%S', '%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M', HOURS, MINUTES, SECONDS]
@click.command()
@click.argument("enddate", type=DateTime(formats=DATETIME_FORMAT))
def main(enddate):
@ -36,7 +53,7 @@ def main(enddate):
root.configure(background="#000")
tlbl = Label(root, text="", font=("Arial", -100), fg="#fff", bg="#000")
tlbl.pack()
tlbl.place(relx=.5, rely=.5, anchor=CENTER)
tlbl.place(relx=0.5, rely=0.5, anchor=CENTER)
def deltaStr(t):
days, remainder = divmod(t.total_seconds(), 60 * 60 * 24)
@ -52,7 +69,7 @@ def main(enddate):
def resize(_):
ratio = root.winfo_width() / 1920
tlbl.configure(font=('Chicago', int(ratio * -200)))
tlbl.configure(font=("Chicago", int(ratio * -200)))
def update():
delta = enddate - datetime.datetime.now()
@ -66,7 +83,7 @@ def main(enddate):
root.bind("<Configure>", resize)
root.bind("<Escape>", lambda x: root.destroy())
root.after(1, update)
root.wm_attributes('-type', 'splash')
root.wm_attributes("-type", "splash")
root.mainloop()