anonymize_5.py 405 B

123456789101112131415
  1. def replace_nhs_numbers(fn, locations):
  2. outFn = os.path.join(os.path.dirname(fn), "ANON_" + os.path.basename(fn))
  3. with open(fn, 'rb') as f, open(outFn, 'wb') as out:
  4. for location in locations:
  5. buf = f.read(location - f.tell())
  6. out.write(buf)
  7. pseudo = str(get_pseudonym((int(f.read(10)))))
  8. out.write(pseudo)
  9. out.write(f.read())