attribution.py 899 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python
  2. from __future__ import absolute_import, unicode_literals
  3. import fileinput
  4. from pprint import pprint
  5. def author(line):
  6. try:
  7. A, E = line.strip().rsplit(None, 1)
  8. E.replace('>', '').replace('<', '')
  9. except ValueError:
  10. A, E = line.strip(), None
  11. return A.lower() if A else A, E.lower() if E else E
  12. def proper_name(name):
  13. return name and ' ' in name
  14. def find_missing_authors(seen):
  15. with open('AUTHORS') as authors:
  16. known = [author(line) for line in authors.readlines()]
  17. seen_authors = {t[0] for t in seen if proper_name(t[0])}
  18. known_authors = {t[0] for t in known}
  19. # maybe later?:
  20. # seen_emails = {t[1] for t in seen}
  21. # known_emails = {t[1] for t in known}
  22. pprint(seen_authors - known_authors)
  23. if __name__ == '__main__':
  24. find_missing_authors([author(line) for line in fileinput.input()])