anonymize_7.py 941 B

123456789101112131415161718192021222324252627282930313233
  1. def load_pseudonyms():
  2. global GENERATE_NEW
  3. dirs = [os.path.abspath(os.path.dirname(fn)) for fn in sys.argv]
  4. dirs = list(set(dirs))
  5. for dir_ in dirs:
  6. fn = os.path.join(dir_, "pseudonyms.csv")
  7. try:
  8. reader = csv.reader(open(fn, 'r'))
  9. except IOError:
  10. continue
  11. print("Reading pseudonyms from %s" % fn)
  12. for line in reader:
  13. if len(line) > 0:
  14. try:
  15. LOOKUP[int(line[0])] = int(line[1])
  16. except ValueError:
  17. pass
  18. num_loaded = len(LOOKUP)
  19. if num_loaded == 0:
  20. print("I haven't loaded any pseudonyms, should I just generate a "
  21. "pseudonym for every NHS number I encounter?")
  22. if raw_input("Type y or n: ") == 'y':
  23. GENERATE_NEW = True
  24. else:
  25. print("Loaded %d pseudonyms NHS numbers." % num_loaded)
  26. GENERATE_NEW = False