-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff_util.py
More file actions
28 lines (24 loc) · 951 Bytes
/
diff_util.py
File metadata and controls
28 lines (24 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# diff_util.py
from deepdiff import DeepDiff
TIME_KEYWORDS = ["لحظاتی پیش", "دقایقی پیش", "ساعت"]
def is_time_change(old, new):
if not isinstance(old, str) or not isinstance(new, str):
return False
return any(k in old for k in TIME_KEYWORDS) and any(k in new for k in TIME_KEYWORDS)
def filter_deepdiff(diff):
"""Filter DeepDiff result to remove timestamp-only changes."""
filtered = {}
for change_type, items in diff.items():
keep = {}
for k, v in items.items():
if isinstance(v, dict) and "old_value" in v and "new_value" in v:
if not is_time_change(v.get("old_value"), v.get("new_value")):
keep[k] = v
else:
keep[k] = v
if keep:
filtered[change_type] = keep
return filtered
def compute_diff(old, new):
d = DeepDiff(old, new, ignore_order=True)
return filter_deepdiff(d)