-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
39 lines (28 loc) · 1.1 KB
/
main.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
import json
import os
from helper.api import CodeWarsApi
from helper.kata import KataParser
with open('./setup.json') as fin:
setup = json.load(fin)
with open('./source.html') as fin:
file = fin.read()
base_dir = setup['download_folder']
extensions = setup['file_extensions']
parser = KataParser(file)
katas = parser.parse_katas()
api = CodeWarsApi(setup['codewars']['api_key'])
print('Exporting katas...')
for i, kata in enumerate(katas):
print('\r{}/{} katas exported.'.format(i+1, len(katas)), end='')
kata_description = api.get_kata_description(kata.kata_id)
for language, source_code in zip(kata.languages, kata.source_codes):
file_dir = os.path.join(
base_dir, language, kata.difficulty, kata.title,)
print(file_dir)
if not os.path.exists(file_dir):
os.makedirs(file_dir)
filename = 'solution' + extensions.get(language, '')
with open(os.path.join(file_dir, filename), 'w') as fout:
fout.write(source_code)
with open(os.path.join(file_dir, 'README.md'), 'w') as fout:
fout.write(kata_description)