adding definition for timespans for ls and acc command
This commit is contained in:
35
main.py
35
main.py
@@ -1,31 +1,52 @@
|
||||
#!/usr/bin/python3
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from util.str_to_datetime import str_to_datetime as datetime
|
||||
from util.str_to_datetime import str_to_datetime
|
||||
|
||||
from model.TimeSlotContainer import time_slot_container as tsc
|
||||
from model.TimeSlot import TimeSlot
|
||||
|
||||
from util.views import convert_to_table
|
||||
from util.parser import create_parser
|
||||
from util import timeslotlist
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = create_parser()
|
||||
args = parser.parse_args()
|
||||
|
||||
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()
|
||||
|
||||
if args.command == "ls":
|
||||
print(convert_to_table(tsc.get_time_slots_by_date()))
|
||||
print(convert_to_table(slots))
|
||||
|
||||
elif args.command == "start":
|
||||
if args.start is not None:
|
||||
tsc.open_time_slot(args.name, datetime(args.start))
|
||||
tsc.open_time_slot(args.name, str_to_datetime(args.start))
|
||||
else:
|
||||
tsc.open_time_slot(args.name)
|
||||
print(f"Started event {args.name}.")
|
||||
|
||||
elif args.command == "end":
|
||||
if args.end is not None:
|
||||
tsc.close_time_slot(datetime(args.end))
|
||||
tsc.close_time_slot(str_to_datetime(args.end))
|
||||
else:
|
||||
tsc.close_time_slot()
|
||||
print("Ended event.")
|
||||
@@ -34,8 +55,8 @@ if __name__ == "__main__":
|
||||
print(convert_to_table(tsc.get_open_time_slots()))
|
||||
|
||||
elif args.command == "add":
|
||||
tsc.add_time_slot(args.name, datetime(args.start), datetime(args.end))
|
||||
tsc.add_time_slot(args.name, str_to_datetime(args.start), str_to_datetime(args.end))
|
||||
|
||||
elif args.command == "acc":
|
||||
d = tsc.accumulate_duration(args.query)
|
||||
print(f"{d.seconds // 3600}:{d.seconds % 3600 // 60}")
|
||||
d = timeslotlist.accumulate_duration(timeslotlist.filter(slots, args.query))
|
||||
print(f"{d.seconds // 3600}:{d.seconds % 3600 // 60:02}")
|
||||
|
||||
Reference in New Issue
Block a user