hash_list.py 655 B

123456789101112131415161718192021222324
  1. import hashlib
  2. import io
  3. from pathlib import Path
  4. def get_hash(filename):
  5. with open(filename, "r", encoding="latin-1", buffering=0) as frh:
  6. with open(filename + ".sha", "w", encoding="latin-1") as fwh:
  7. chunk = io.StringIO()
  8. for i, line in enumerate(frh.readlines()):
  9. chunk.write(line)
  10. if i % 1000 == 0:
  11. m = hashlib.sha256(chunk.getvalue().encode())
  12. chunk.truncate(0)
  13. fwh.write(m.hexdigest() + "\n")
  14. def main():
  15. for f in Path("datev/data").glob("*.csv"):
  16. get_hash(str(f))
  17. if __name__ == "__main__":
  18. main()