Download SDC/CalcSHA1v2.py from pebxcvi/PSHomeCacheDepot: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/datasets/pebxcvi/PSHomeCacheDepot/resolve/33f49785f2fbff03f9beda25e49ea182999a9fc3/SDC/CalcSHA1v2.py
- Command line
-
hf download hf://datasets/pebxcvi/PSHomeCacheDepot@33f49785f2fbff03f9beda25e49ea182999a9fc3/SDC/CalcSHA1v2.py
-
curl -L -o CalcSHA1v2.py https://huggingface.co/datasets/pebxcvi/PSHomeCacheDepot/resolve/33f49785f2fbff03f9beda25e49ea182999a9fc3/SDC/CalcSHA1v2.py
1.29 kB
| import hashlib | |
| import os | |
| def calculate_sha1(file_path): | |
| sha1 = hashlib.sha1() | |
| with open(file_path, 'rb') as file: | |
| while True: | |
| data = file.read(8192) # Reading chunks of 8KB | |
| if not data: | |
| break | |
| sha1.update(data) | |
| return sha1.hexdigest().upper() # Returning the hash in uppercase | |
| def find_files_and_calculate_sha1(): | |
| current_directory = os.getcwd() | |
| extensions = ('.sdc') | |
| output_file = "sha1_hashes.txt" | |
| with open(output_file, 'w') as out_file: | |
| counter = 0 | |
| for root, dirs, files in os.walk(current_directory): | |
| for file in files: | |
| # Convert file name to lowercase before extension check | |
| if file.lower().endswith(extensions): | |
| file_path = os.path.join(root, file) | |
| relative_path = os.path.relpath(file_path, start=current_directory) | |
| sha1_hash = calculate_sha1(file_path) | |
| out_file.write(f"{relative_path}\t{sha1_hash}\n") | |
| counter += 1 | |
| print(f"{counter}. Processing: {relative_path}") | |
| print(f"SHA1 hashes written to {output_file}") | |
| # Calling the function to execute the hash calculation | |
| find_files_and_calculate_sha1() | |