Download ODC/CalcSHA1.py from pebxcvi/PSHomeCacheDepot: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/datasets/pebxcvi/PSHomeCacheDepot/resolve/c7e5147d4bcd9307496297caec96782686eed17a/ODC/CalcSHA1.py
- Command line
-
hf download hf://datasets/pebxcvi/PSHomeCacheDepot@c7e5147d4bcd9307496297caec96782686eed17a/ODC/CalcSHA1.py
-
curl -L -o CalcSHA1.py https://huggingface.co/datasets/pebxcvi/PSHomeCacheDepot/resolve/c7e5147d4bcd9307496297caec96782686eed17a/ODC/CalcSHA1.py
1.15 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() | |
| # Define the tuple of extensions to include in the search | |
| extensions = ('.odc') | |
| # Modify the list comprehension to search for files with the new extensions | |
| files = [f for f in os.listdir(current_directory) if f.endswith(extensions)] | |
| output_file = "sha1_hashes.txt" | |
| with open(output_file, 'w') as out_file: | |
| for counter, file in enumerate(files, start=1): | |
| file_path = os.path.join(current_directory, file) | |
| sha1_hash = calculate_sha1(file_path) | |
| out_file.write(f"{file}\t{sha1_hash}\n") | |
| print(f"{counter}. Processing: {file}") | |
| print(f"SHA1 hashes written to {output_file}") | |
| # Calling the updated function | |
| find_files_and_calculate_sha1() | |