Created
January 9, 2022 16:11
-
-
Save iainnash/bc977015d34f844242b6d995a9efd004 to your computer and use it in GitHub Desktop.
sort ipfs files output by filename into json file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import glob | |
import json | |
INPUT_FILE = 'files-test.txt' | |
OUTPUT_FILE = 'output-hashes.json' | |
data = [] | |
with open(INPUT_FILE, 'r') as f: | |
data = f.readlines() | |
hashes_by_id = {} | |
for indx, file in enumerate(data): | |
print(file, indx) | |
[hash, _, fnameraw] = re.split(r'[ ]+', file) | |
[fname, ext] = fnameraw.strip().split('.') | |
hashes_by_id[fname] = hash | |
output_hashes = [] | |
for i in range(len(data)): | |
key = str(i+1) | |
try: | |
output_hashes.append(hashes_by_id[key]) | |
except: | |
print('cannot find key ', key) | |
with open(OUTPUT_FILE, 'w') as f: | |
json.dump(output_hashes, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment