File size: 774 Bytes
3b53130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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:
        # check if file exist
        if not file_exists("./data/" + d.get("file_name")):
            print("File not found: " + d.get("file_name"))
            continue
        # write to new JSONL file
        with open("./data/metadata-pruned.jsonl", "a") as f:
            f.write(json.dumps(d) + "\n")
        count +=1
        # print(d.get("file_name"))
    print(len(data))
    print(count)