Files
tt/main.py

42 lines
1.2 KiB
Python
Raw Normal View History

2024-06-13 09:40:09 +02:00
#!/usr/bin/python3
2025-11-13 19:04:55 +01:00
from util.str_to_datetime import str_to_datetime as 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
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
2024-06-13 10:21:19 +02:00
if args.command == "ls":
2024-06-19 22:53:43 +02:00
print(convert_to_table(tsc.get_time_slots_by_date()))
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:
tsc.open_time_slot(args.name, 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:
tsc.close_time_slot(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
elif args.command == "ps":
2024-06-19 22:53:43 +02:00
print(convert_to_table(tsc.get_open_time_slots()))
elif args.command == "add":
2024-06-19 22:53:43 +02:00
tsc.add_time_slot(args.name, datetime(args.start), datetime(args.end))
2025-11-13 19:04:55 +01:00
elif args.command == "acc":
d = tsc.accumulate_duration(args.query)
print(f"{d.seconds // 3600}:{d.seconds % 3600 // 60}")