-
Notifications
You must be signed in to change notification settings - Fork 0
/
format.py
33 lines (24 loc) · 875 Bytes
/
format.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
# Spaghetti code, pls ignore
from sys import argv
import json
def formatter(filename):
with open(f'{filename}.json', 'r', encoding='utf-8') as f:
original = json.load(f)
with open(f'{filename}_formatted.json', 'w', encoding='utf-8') as formatted:
formatted.write('')
with open(f'{filename}_formatted.json', 'a', encoding='utf-8') as appendfile:
for key, value in original.items():
player = {
'id': int(value),
'name': key
}
playerformatted = json.dumps(player, indent=4)
appendfile.write(playerformatted)
appendfile.write(',\n')
def main():
try:
filename = str(argv[1])
except IndexError:
return print('You need to input a file name')
formatter(filename)
main()