Skip to content

Commit

Permalink
Merge pull request #36 from sam-kleiner/main
Browse files Browse the repository at this point in the history
add recursive_merge_lists
  • Loading branch information
meeb authored Jul 29, 2024
2 parents b4f7f0e + 5524855 commit 13e667e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions whoisit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,18 @@ def recursive_merge(d1, d2):
for k, v in d2.items():
if k in d1 and isinstance(d1[k], dict) and isinstance(v, dict):
recursive_merge(d1[k], v)
elif k == "events" and isinstance(v, list):
v1 = d1.get(k) or []
d1[k] = recursive_merge_lists(v1, v, dedup_on='eventAction')
elif k in {"notices", "remarks"} and isinstance(v, list):
v1 = d1.get(k) or []
d1[k] = recursive_merge_lists(v1, v)
elif v:
d1[k] = v


def recursive_merge_lists(l1, l2, dedup_on="title"):
list1 = {l[dedup_on]: l for l in l1}
list2 = {l[dedup_on]: l for l in l2}
recursive_merge(list1, list2)
return list(list1.values())

0 comments on commit 13e667e

Please sign in to comment.