#!/usr/bin/env python3 """Troca por nomes inventados os pilotos fantasma cujo nome coincide com o de pessoas conhecidas (ver build-ghost-car-challenge.sh). Uso: python3 -I rename-drivers.py . Mexe em track/**/*.json e js/banned_names.js; cada nome precisa existir.""" import sys from pathlib import Path root = Path(sys.argv[1]) NAMES = { 'Jim Brown': 'Jory Brandt', 'Nick Ross': 'Nils Roth', 'Gordon P. Moore': 'Gideon P. Moorfield', 'Martin D. Cooper': 'Marlon D. Cowper', 'Paul M. Allen': 'Pavel M. Allard', 'Steve N. Wright': 'Stefan N. Wrightson', } files = sorted(root.glob('track/**/*.json')) + [root / 'js' / 'banned_names.js'] found = dict.fromkeys(NAMES, 0) for f in files: text = f.read_text(encoding='utf-8') new = text for old, repl in NAMES.items(): found[old] += new.count(f'"{old}"') new = new.replace(f'"{old}"', f'"{repl}"') if new != text: f.write_text(new, encoding='utf-8') missing = [n for n, c in found.items() if c == 0] if missing: sys.exit(f'rename-drivers.py: nao achei {missing}')