From 5979454312178fdf96b0fb488ecfdbddbbf87c96 Mon Sep 17 00:00:00 2001 From: Ricardo Bartels Date: Sat, 13 Jul 2024 11:04:00 +0200 Subject: [PATCH] imporves call log parser code readability #122 --- .../service_definitions/telephone_list.py | 53 +++++++++++-------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/fritzinfluxdb/classes/fritzbox/service_definitions/telephone_list.py b/fritzinfluxdb/classes/fritzbox/service_definitions/telephone_list.py index dc96437..72561a7 100644 --- a/fritzinfluxdb/classes/fritzbox/service_definitions/telephone_list.py +++ b/fritzinfluxdb/classes/fritzbox/service_definitions/telephone_list.py @@ -77,30 +77,39 @@ def get_call_duration(field) -> int: return duration + @property def hash(self) -> str: return self._hash + @property def type(self) -> str: return self._call_type + @property def date_time(self) -> datetime: return self._date_time + @property def caller_name(self) -> str: return self._caller_name.strip('"') + @property def caller_number(self) -> str: return self._caller_number.strip('"') + @property def caller_location(self) -> str: return self._caller_location.strip('"') + @property def extension(self) -> str: return self._extension.strip('"') + @property def number_called(self) -> str: return self._number_called.strip('"') + @property def duration(self) -> int: return self._duration @@ -108,7 +117,7 @@ def duration(self) -> int: class CallLog: """ Parse FritzBox call log entries csv list - extracts separator and header and + extracts separator and header, parses each line with given seperator """ new_line_char = "\n" @@ -170,9 +179,9 @@ def __init__(self, data): "value_function": lambda data: data, "next": { "type": str, - "tags_function": lambda entry: {"uid": entry.hash()}, - "value_function": lambda entry: entry.type(), - "timestamp_function": lambda entry: entry.date_time(), + "tags_function": lambda entry: {"uid": entry.hash}, + "value_function": lambda entry: entry.type, + "timestamp_function": lambda entry: entry.date_time, } }, "call_list_caller_name": { @@ -180,9 +189,9 @@ def __init__(self, data): "value_function": lambda data: data, "next": { "type": str, - "tags_function": lambda entry: {"uid": entry.hash()}, - "value_function": lambda entry: entry.caller_name(), - "timestamp_function": lambda entry: entry.date_time(), + "tags_function": lambda entry: {"uid": entry.hash}, + "value_function": lambda entry: entry.caller_name, + "timestamp_function": lambda entry: entry.date_time, } }, "call_list_caller_number": { @@ -190,9 +199,9 @@ def __init__(self, data): "value_function": lambda data: data, "next": { "type": str, - "tags_function": lambda entry: {"uid": entry.hash()}, - "value_function": lambda entry: entry.caller_number(), - "timestamp_function": lambda entry: entry.date_time(), + "tags_function": lambda entry: {"uid": entry.hash}, + "value_function": lambda entry: entry.caller_number, + "timestamp_function": lambda entry: entry.date_time, } }, "call_list_caller_location": { @@ -200,9 +209,9 @@ def __init__(self, data): "value_function": lambda data: data, "next": { "type": str, - "tags_function": lambda entry: {"uid": entry.hash()}, - "value_function": lambda entry: entry.caller_location(), - "timestamp_function": lambda entry: entry.date_time(), + "tags_function": lambda entry: {"uid": entry.hash}, + "value_function": lambda entry: entry.caller_location, + "timestamp_function": lambda entry: entry.date_time, } }, "call_list_extension": { @@ -210,9 +219,9 @@ def __init__(self, data): "value_function": lambda data: data, "next": { "type": str, - "tags_function": lambda entry: {"uid": entry.hash()}, - "value_function": lambda entry: entry.extension(), - "timestamp_function": lambda entry: entry.date_time(), + "tags_function": lambda entry: {"uid": entry.hash}, + "value_function": lambda entry: entry.extension, + "timestamp_function": lambda entry: entry.date_time, } }, "call_list_number_called": { @@ -220,9 +229,9 @@ def __init__(self, data): "value_function": lambda data: data, "next": { "type": str, - "tags_function": lambda entry: {"uid": entry.hash()}, - "value_function": lambda entry: entry.number_called(), - "timestamp_function": lambda entry: entry.date_time(), + "tags_function": lambda entry: {"uid": entry.hash}, + "value_function": lambda entry: entry.number_called, + "timestamp_function": lambda entry: entry.date_time, } }, "call_list_duration": { @@ -230,9 +239,9 @@ def __init__(self, data): "value_function": lambda data: data, "next": { "type": int, - "tags_function": lambda entry: {"uid": entry.hash()}, - "value_function": lambda entry: entry.duration(), - "timestamp_function": lambda entry: entry.date_time(), + "tags_function": lambda entry: {"uid": entry.hash}, + "value_function": lambda entry: entry.duration, + "timestamp_function": lambda entry: entry.date_time, } } }