rprp / write_back.py
yilunzhao's picture
Duplicate from mmya/10K_papers
5e81459 verified
import os
import json
from tqdm import tqdm
# ่ฆ้ๅކ็š„็›ฎๅฝ•
base_dir = "/home/yz979/palmer_scratch/chengye/1000_arxiv/pdf2figure/data"
json_files = []
file_names = []
# ้ๅކ็›ฎๅฝ•
for root, dirs, files in os.walk(base_dir):
for file in files:
if file.endswith(".json"):
full_path = os.path.join(root, file)
json_files.append(full_path)
file_names.append(file)
for i in tqdm(range(0,len(json_files))):
table = {}
with open(json_files[i],'r',encoding='utf-8')as f:
data = json.load(f)
for item in data:
if item['figType'] == 'Table':
item['renderURL'] = item['renderURL'].split('/')[-1]
item.pop("imageText", None)
table[item['name']] = item
paper_path = '/home/yz979/palmer_scratch/chengye/1000_arxiv/papers/'+file_names[i]
with open(paper_path,'r',encoding='utf-8')as f:
data = json.load(f)
data['new_table'] = table
with open(paper_path, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)