-
Notifications
You must be signed in to change notification settings - Fork 3
/
write_problems.py
executable file
·49 lines (41 loc) · 1.05 KB
/
write_problems.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /usr/bin/env python
import sys
from re import match
from aparser import parse_generic as parse
import json
ofile ="athena_problems.json"
if len(sys.argv) > 1:
ifile = sys.argv[1]
else:
ifile = 'inputs.txt'
file = open(ifile, 'r')
print("input: ",ifile)
line = file.readline()
dict = {}
athena = last = None
while line:
m = match('./([^/]+)/', line)
if m:
info = None
last = athena
athena = m.group(1)
clean_line = line.split()[0]
problem = clean_line.split('/')[-1].split('.')[0 if athena == 'athenak' else 1]
try:
_, info, _ = parse(clean_line, True)
except:
pass
if athena != last:
dict[athena] = {}
try:
dict[athena][info['problem']] = clean_line
except:
dict[athena][problem] = clean_line
line = file.readline()
# Serializing json
json_object = json.dumps(dict, indent=3)
# Writing to sample.json
with open(ofile, "w") as outfile:
outfile.write(json_object)
file.close()
print("output:",ofile)