-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextracting solutions from json.py
More file actions
76 lines (56 loc) · 1.69 KB
/
extracting solutions from json.py
File metadata and controls
76 lines (56 loc) · 1.69 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
import json
sep = os.sep
f = open('pctablet505_data.json')
data = json.load(f)
f.close()
c = 0
i = 0
failures = []
languages = set()
banned = ['\\', '/', '!', '*', '"', '<', '>', '?', ':']
for ind, sub in enumerate(data['submissions']):
if sub['score'] > 2:
contest = sub['contest']
fname = sub['challenge']
lang = sub['language']
languages.add(lang)
for x in banned:
fname = fname.replace(x, '')
if lang in ('python', 'python3'):
ext = '.py'
elif lang == 'pypy3':
ext = '.pypy'
elif lang == 'c':
ext = '.c'
elif lang == "cpp" or lang == 'cpp14':
ext = '.cpp'
elif lang == "java" or lang == 'java8':
ext = '.java'
elif lang == 'javascript':
ext = '.js'
else:
ext = '.' + sub['language']
path = 'hackerrank' + sep
try:
if lang in ['db2', 'mysql', 'oracle']:
path += 'SQL' + sep
elif lang == 'javascript':
path += 'JavaScript' + sep
else:
path += contest + sep
if not os.path.exists(path):
os.makedirs(path)
if 'code' not in sub:
failures.append((fname, ind))
continue
if os.path.exists(path + fname + ext):
continue
with open(path + fname + ext, 'w') as f:
f.write(sub['code'])
except:
print(fname, ind)
failures.append((fname, ind))
c += 1
i += 1
print(i, c)