Commit 0dd6f9d4 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

implement Pipeline.message.write() and Pipeline.timestamp.record()

parent 43be4795
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -266,18 +266,21 @@ class Message:
    def __repr__(self):
        return f"< Message [{self.file_path}] >"

    def write(self, dlist):
    def write(self, dlist: list[dict]):
        """Write messages to file."""
        with open(self.file_path, "w+") as f:
            for d in dlist:
                f.write(self.dict2msg(d) + "\n")

    @staticmethod
    def dict2msg(d):
    def dict2msg(d: dict):
        """Convert `dict` to JSON format string."""
        m = json.dumps(d).replace(" ", "")
        return m

    @staticmethod
    def msg2dict(m):
    def msg2dict(m: str):
        """Convert JSON format string to `dict`."""
        d = json.loads(m)
        return d

@@ -322,8 +325,8 @@ class Timestamp:
        with open(self.file_path, "w") as file:
            file.truncate(0)

    def touch(self):
        """Write a time stamp."""
    def record(self):
        """Record a time stamp."""
        with open(self.file_path, "a+") as f:
            f.write(f"{Time.now().isot}+00:00\n")