rms-support-letter.github.io/find-duplicates.py

27 lines
955 B
Python
Raw Normal View History

2021-03-26 21:58:31 +01:00
import os
from collections import defaultdict
2021-03-28 09:47:55 +02:00
file_name_by_name = defaultdict(list)
2021-03-26 21:58:31 +01:00
file_name_by_link = defaultdict(list)
for file_name in sorted(os.listdir("_data/signed")):
with open(f"_data/signed/{file_name}") as f:
contents = f.read().replace("\r", "")
2021-03-28 09:47:55 +02:00
name = next(line for line in contents.split("\n") if line.startswith("name:"))[5:].strip()
2021-03-26 21:58:31 +01:00
link = next(line for line in contents.split("\n") if line.startswith("link:"))[5:].strip()
2021-03-28 09:47:55 +02:00
if name[0] == name[0].lower() or " " in name: # looks like a nickname or a full name
file_name_by_name[name].append(file_name)
if link != "/#":
file_name_by_link[link].append(file_name)
for name, file_names in file_name_by_name.items():
if len(file_names) == 1:
2021-03-26 21:58:31 +01:00
continue
2021-03-28 09:47:55 +02:00
print(name, "duplicates:", file_names)
2021-03-26 21:58:31 +01:00
for link, file_names in file_name_by_link.items():
if len(file_names) == 1:
continue
print(link, "duplicates:", file_names)