Skip to content

Commit 8737c07

Browse files
committed
update script to exclude names
1 parent 506c96a commit 8737c07

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

script/premint/generate_batch_renewals.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ def parse_arguments():
7474
)
7575
return parser.parse_args()
7676

77+
def load_excluded_names(script_dir: Path) -> set:
78+
"""Load names to exclude from the lostnames file."""
79+
lostnames_file = script_dir / "lostnames"
80+
excluded_names = set()
81+
82+
if lostnames_file.exists():
83+
with open(lostnames_file, 'r') as f:
84+
for line in f:
85+
name = line.strip()
86+
if name:
87+
excluded_names.add(name.lower()) # Store in lowercase for case-insensitive comparison
88+
89+
return excluded_names
90+
7791
def main():
7892
"""Main function to generate the CSV file."""
7993

@@ -83,12 +97,17 @@ def main():
8397
# Path to the input and output files
8498
input_file = Path(args.input_file)
8599
output_file = Path(args.output)
100+
script_dir = Path(__file__).parent
86101

87102
# Check if input file exists
88103
if not input_file.exists():
89104
print(f"Error: Input file '{input_file}' not found.")
90105
return 1
91106

107+
# Load excluded names from lostnames file
108+
excluded_names = load_excluded_names(script_dir)
109+
print(f"Loaded {len(excluded_names)} excluded names from lostnames file")
110+
92111
# Calculate duration in seconds
93112
duration_seconds = calculate_duration_in_seconds(args.duration)
94113
print(f"Duration: {args.duration} years ({duration_seconds} seconds)")
@@ -99,11 +118,17 @@ def main():
99118
seen_ids = set()
100119
unique_entries = []
101120
duplicate_names = []
121+
excluded_names_found = []
102122

103123
with open(input_file, 'r') as infile:
104124
for line_num, line in enumerate(infile, 1):
105125
name = line.strip()
106126
if name: # Skip empty lines
127+
# Check if name is in excluded list (case-insensitive)
128+
if name.lower() in excluded_names:
129+
excluded_names_found.append((line_num, name))
130+
continue
131+
107132
name_id = keccak256_to_uint(name)
108133
if name_id not in seen_ids:
109134
seen_ids.add(name_id)
@@ -126,18 +151,27 @@ def main():
126151
total_names = sum(1 for line in open(input_file) if line.strip())
127152
unique_count = len(unique_entries)
128153
duplicate_count = len(duplicate_names)
154+
excluded_count = len(excluded_names_found)
129155

130156
print(f"CSV file generated: {output_file}")
131157
print(f"Total names processed: {total_names}")
132158
print(f"Unique entries written: {unique_count}")
133159
print(f"Duplicates found and skipped: {duplicate_count}")
160+
print(f"Excluded names found and skipped: {excluded_count}")
134161

135162
if duplicate_names:
136163
print("\nDuplicate names found:")
137164
for line_num, name in duplicate_names:
138165
print(f" Line {line_num}: {name}")
139166
else:
140167
print("No duplicates found.")
168+
169+
if excluded_names_found:
170+
print("\nExcluded names found (from lostnames):")
171+
for line_num, name in excluded_names_found:
172+
print(f" Line {line_num}: {name}")
173+
else:
174+
print("No excluded names found.")
141175
return 0
142176

143177
if __name__ == "__main__":

0 commit comments

Comments
 (0)