|
import json |
|
import os |
|
|
|
def file_exists(file_path): |
|
return os.path.isfile(file_path) |
|
|
|
def read_jsonl(file_path): |
|
data = [] |
|
with open(file_path, 'r') as f: |
|
for line in f: |
|
data.append(json.loads(line)) |
|
return data |
|
|
|
if __name__ == "__main__": |
|
count = 0 |
|
data = read_jsonl("./data/metadata.jsonl") |
|
print(len(data)) |
|
for d in data: |
|
|
|
if not file_exists("./data/" + d.get("file_name")): |
|
print("File not found: " + d.get("file_name")) |
|
continue |
|
|
|
with open("./data/metadata-pruned.jsonl", "a") as f: |
|
f.write(json.dumps(d) + "\n") |
|
count +=1 |
|
|
|
print(len(data)) |
|
print(count) |