Guest User

Untitled

a guest
Feb 19th, 2018
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. # A python script which anonymizes email addresses in all files in current directory and sub-directories.
  2. # e.g. A file with the following contents:
  3.  
  4. # siddhartha@gmail.com
  5. # Sid Phn#- 6385833322
  6. # gupta49@illinois.edu
  7. # weee@as.cd
  8. # sid@yahoo.co.in
  9.  
  10. # Would change to:
  11.  
  12. # xxxx@gmail.com
  13. # Sid Phn#- 6385833322
  14. # xxxx@illinois.edu
  15. # xxxx@as.cd
  16. # xxxx@yahoo.co.in
  17.  
  18. import os
  19. import re
  20. from os.path import join, getsize, isfile
  21.  
  22. def main():
  23.  
  24. for root, dirs, files in os.walk('.'):
  25. for filename in files:
  26. if not filename.startswith('.'):
  27. filename = join(root, filename)
  28. myfile = open(filename, 'r')
  29. content = myfile.read()
  30. content = re.sub(r'.+(?=@.+\.(.+))', "xxxx", content)
  31. myfile = open(filename, 'w')
  32. myfile.write(content)
  33. myfile.close()
  34.  
  35. # Call the main function.
  36. main()
Add Comment
Please, Sign In to add comment