anonymize_3.py 586 B

1234567891011121314151617181920212223
  1. def find_nhs_numbers(fn):
  2. try:
  3. f = open(fn, 'rb')
  4. except IOError:
  5. return None
  6. locations = []
  7. num = 0
  8. while True:
  9. c = f.read(1)
  10. if c == '':
  11. break
  12. ascii_ = ord(c)
  13. if ascii_ in (48, 49, 50, 51, 52, 53, 54, 55, 56, 57):
  14. num += 1
  15. else:
  16. if num == 10:
  17. startLocation = f.tell() - 11
  18. f.seek(startLocation)
  19. if validate_nhs_number(f.read(10)):
  20. locations.append(startLocation)
  21. num = 0
  22. return locations