add nice output for ls

This commit is contained in:
2024-06-13 10:38:43 +02:00
parent 0abf886d11
commit ce461bd087
3 changed files with 21 additions and 2 deletions

View File

@@ -28,7 +28,9 @@ class TimeSlot():
@property @property
def end(self): def end(self):
return datetime.fromtimestamp(self._end) if "_end" in self.__dict__:
return datetime.fromtimestamp(self._end)
return None
@end.setter @end.setter
def end(self, d: datetime): def end(self, d: datetime):

16
lib/ui.py Normal file
View File

@@ -0,0 +1,16 @@
from .TimeSlot import TimeSlot
def convert_to_table(time_slot_list: list[TimeSlot]):
widths = [20, 26, 26]
r_str = f"+{'-'*(widths[0]+2)}+{'-'*(widths[1]+2)}+{'-'*(widths[2]+2)}+\n"
r_str += f"| {'Name':<20} | {'Startzeitpunkt':<26} | {'Endzeitpunkt':<26} |\n"
r_str += f"+{'-'*(widths[0]+2)}+{'-'*(widths[1]+2)}+{'-'*(widths[2]+2)}+\n"
for time_slot in time_slot_list:
r_str += f"| {time_slot.name:<20} | {str(time_slot.start):<26} | {str(time_slot.end):<26} |\n"
r_str += f"+{'-'*(widths[0]+2)}+{'-'*(widths[1]+2)}+{'-'*(widths[2]+2)}+"
return r_str

View File

@@ -3,6 +3,7 @@
import argparse import argparse
from lib.DataStore import DataStore from lib.DataStore import DataStore
from lib.TimeSlot import TimeSlot from lib.TimeSlot import TimeSlot
from lib.ui import convert_to_table
if __name__ == "__main__": if __name__ == "__main__":
@@ -16,4 +17,4 @@ if __name__ == "__main__":
ds = DataStore("data.json") ds = DataStore("data.json")
if args.command == "ls": if args.command == "ls":
print(ds.get_all_time_slots()) print(convert_to_table(ds.get_all_time_slots()))