forked from VikParuchuri/marker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_jsonfile.py
34 lines (23 loc) · 858 Bytes
/
gen_jsonfile.py
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
30
31
32
33
34
import os
import json
import sys
def gen_json_file(input_dir, output_dir):
metadata = {}
for filename in os.listdir(input_dir):
if filename.endswith('.pdf'):
metadata[filename] = {"languages": ["Chinese", "English"]}
output_path = os.path.join(output_dir, "metadata.json")
with open(output_path, "w", encoding='utf-8') as json_file:
json.dump(metadata, json_file, ensure_ascii=False, indent=4)
def main():
if len(sys.argv) != 2:
print("Usage: python gen_jsonfile.py <input_directory>")
sys.exit(1)
input_dir = sys.argv[1]
if not os.path.isdir(input_dir):
print(f"Input directory {input_dir} does not exist.")
sys.exit(1)
gen_json_file(input_dir, input_dir)
print(f"Metadata file has been created in {input_dir}")
if __name__ == "__main__":
main()