2024-06-13 09:40:09 +02:00
|
|
|
#!/usr/bin/python3
|
2025-11-25 11:52:10 +01:00
|
|
|
from datetime import datetime, timedelta
|
2024-06-13 09:40:09 +02:00
|
|
|
|
2025-11-25 11:52:10 +01:00
|
|
|
from util.str_to_datetime import str_to_datetime
|
2024-06-13 09:40:09 +02:00
|
|
|
|
2024-06-19 22:53:43 +02:00
|
|
|
from model.TimeSlotContainer import time_slot_container as tsc
|
2024-06-19 14:55:39 +02:00
|
|
|
from model.TimeSlot import TimeSlot
|
2024-06-13 09:40:09 +02:00
|
|
|
|
2024-06-19 14:55:39 +02:00
|
|
|
from util.views import convert_to_table
|
|
|
|
|
from util.parser import create_parser
|
2025-11-25 11:52:10 +01:00
|
|
|
from util import timeslotlist
|
2024-06-13 11:15:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
parser = create_parser()
|
2024-06-13 10:21:19 +02:00
|
|
|
args = parser.parse_args()
|
2024-06-13 09:40:09 +02:00
|
|
|
|
2025-11-25 11:52:10 +01:00
|
|
|
if args.command in ["ls", "acc"]:
|
|
|
|
|
match args.span:
|
|
|
|
|
case "w":
|
|
|
|
|
start_of_week = datetime.now() - timedelta(days=datetime.now().weekday())
|
|
|
|
|
start_of_week_midnight = start_of_week.replace(hour=0, minute=0, second=0, microsecond=0)
|
|
|
|
|
slots = tsc.get_time_slots_by_date(start=start_of_week_midnight)
|
|
|
|
|
case "lw":
|
|
|
|
|
start_of_week = datetime.now() - timedelta(days=datetime.now().weekday())
|
|
|
|
|
start_of_week_midnight = start_of_week.replace(hour=0, minute=0, second=0, microsecond=0)
|
|
|
|
|
slots = tsc.get_time_slots_by_date(
|
|
|
|
|
start=start_of_week_midnight - timedelta(days=7),
|
|
|
|
|
end=start_of_week_midnight,
|
|
|
|
|
)
|
|
|
|
|
case "d":
|
|
|
|
|
last_midnight = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
|
|
|
|
slots = tsc.get_time_slots_by_date(start=last_midnight)
|
|
|
|
|
case _:
|
|
|
|
|
slots = tsc.get_all_time_slots()
|
|
|
|
|
|
2024-06-13 10:21:19 +02:00
|
|
|
if args.command == "ls":
|
2025-11-25 11:52:10 +01:00
|
|
|
print(convert_to_table(slots))
|
2024-06-13 11:15:48 +02:00
|
|
|
|
|
|
|
|
elif args.command == "start":
|
2024-06-19 22:53:43 +02:00
|
|
|
if args.start is not None:
|
2025-11-25 11:52:10 +01:00
|
|
|
tsc.open_time_slot(args.name, str_to_datetime(args.start))
|
2024-06-13 11:15:48 +02:00
|
|
|
else:
|
2024-06-19 22:53:43 +02:00
|
|
|
tsc.open_time_slot(args.name)
|
|
|
|
|
print(f"Started event {args.name}.")
|
2024-06-13 11:15:48 +02:00
|
|
|
|
|
|
|
|
elif args.command == "end":
|
2024-06-19 22:53:43 +02:00
|
|
|
if args.end is not None:
|
2025-11-25 11:52:10 +01:00
|
|
|
tsc.close_time_slot(str_to_datetime(args.end))
|
2024-06-13 11:15:48 +02:00
|
|
|
else:
|
2024-06-19 22:53:43 +02:00
|
|
|
tsc.close_time_slot()
|
|
|
|
|
print("Ended event.")
|
2024-06-13 11:15:48 +02:00
|
|
|
|
2024-06-13 11:59:46 +02:00
|
|
|
elif args.command == "ps":
|
2024-06-19 22:53:43 +02:00
|
|
|
print(convert_to_table(tsc.get_open_time_slots()))
|
2024-06-13 11:59:46 +02:00
|
|
|
|
|
|
|
|
elif args.command == "add":
|
2025-11-25 11:52:10 +01:00
|
|
|
tsc.add_time_slot(args.name, str_to_datetime(args.start), str_to_datetime(args.end))
|
2025-11-13 19:04:55 +01:00
|
|
|
|
|
|
|
|
elif args.command == "acc":
|
2025-11-25 11:52:10 +01:00
|
|
|
d = timeslotlist.accumulate_duration(timeslotlist.filter(slots, args.query))
|
|
|
|
|
print(f"{d.seconds // 3600}:{d.seconds % 3600 // 60:02}")
|