forked from LuoUndergradXJTU/TwiBot-22
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combine.py
30 lines (28 loc) · 942 Bytes
/
combine.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
import json
import os
import os.path as osp
from argparse import ArgumentParser
from tqdm import tqdm
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('--dataset_name', type=str)
args = parser.parse_args()
path = 'tmp/scores/{}'.format(args.dataset_name)
if not osp.exists(path):
raise ValueError
scores = []
for file in tqdm(os.listdir(path), ncols=0):
try:
data = json.load(open(osp.join(path, file)))
except json.decoder.JSONDecodeError:
continue
if isinstance(data, str):
continue
item = data['cap']
item['id'] = file.replace('.json', '')
scores.append(item)
save_path = 'tmp/output'.format(args.dataset_name)
if not osp.exists(save_path):
os.makedirs(save_path)
print(len(scores))
json.dump(scores, open(osp.join(save_path, '{}.json'.format(args.dataset_name)), 'w'))