forked from kiwiyou/boj-user-translation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
del-tr.py
26 lines (25 loc) · 877 Bytes
/
del-tr.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
from argparse import ArgumentParser
from json import dump, load
import os
parser = ArgumentParser(description="Deletes a translation document.")
parser.add_argument('id')
parser.add_argument('language')
parser.add_argument('author')
args = parser.parse_args()
try:
directory = f'src/{args.id}'
realname = f'{args.language}-{args.author}'
filename = f'{realname}.html'
if os.access(f'{directory}/{filename}', os.F_OK):
os.remove(f'{directory}/{filename}')
print(f'Removed {directory}/{filename}.')
index = load(open('index', 'rt', encoding='utf-8'))
key = str(args.id)
if key in index:
index[key].remove(realname)
if not index[key]:
del index[key]
dump(index, open('index', 'wt', encoding='utf-8'), indent=2, sort_keys=True)
print('Saved index.')
except Exception as e:
print("Error:", e)