-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkdeck
executable file
·59 lines (55 loc) · 1.28 KB
/
mkdeck
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
#!/usr/bin/env python3
import hashlib
import json
import sys
cards = []
with open(sys.argv[1]) as f:
for line in f:
card_name = line.replace("\n", "")
if "[I" in card_name:
info = card_name[3:-1].split(",")
name = info[0]
accent_background = info[1]
accent_color = info[2]
author = info[3]
else:
if "[B" in card_name:
black_card = True
pick = card_name[1:4].split(",")[1]
else:
black_card = False
if black_card:
cards.append({
"id": "b_" + hashlib.sha512(card_name.encode("utf-8")).hexdigest()[0:8],
"content": {
"en": card_name[6:]
},
"pick": int(pick)
})
else:
cards.append({
"id": "w_" + hashlib.sha512(card_name.encode("utf-8")).hexdigest()[0:8],
"content": {
"en": card_name
}
})
semifinal_output = {
"id": None,
"name": name,
"accent_background": accent_background,
"accent_color": accent_color,
"author": author,
"cards": cards
}
identifier = hashlib.sha512(str(semifinal_output).encode("utf-8")).hexdigest()[0:8]
final_output = {
"id": identifier,
"name": name,
"accent_background": accent_background,
"accent_color": accent_color,
"author": author,
"cards": cards
}
filename = sys.argv[1].split(".")[0] + ".json"
with open(filename, "w") as f:
json.dump(final_output, f, indent=4)