forked from GwentCommunityDevelopers/gwent-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gwent.py
52 lines (43 loc) · 1.96 KB
/
gwent.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
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python3
import argparse
import os
import sys
import GwentUtils
from datetime import datetime
import CardData
import KeywordData
import CategoryData
parser = argparse.ArgumentParser(description="Transform the Gwent card data contained in xml files into a "
"standardised JSON format. See README for more info.",
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("inputFolder", help="unzipped data_definitions.zip. Folder containing the xml files.")
parser.add_argument("-l", "--language", help="Includes just the translations for the selected language. Results in much smaller json files. Choose from: en-US, de-DE, es-ES, es-MX, fr-FR, it-IT, ja-JP, ko-KR, pl-PL, pt-BR, ru-RU, zh-CN, zh-TW")
args = parser.parse_args()
rawFolder = args.inputFolder
locale = args.language
if locale:
GwentUtils.LOCALES = [locale]
# Add a backslash on the end if it doesn't exist.
if rawFolder[-1] != "/":
rawFolder = rawFolder + "/"
if not os.path.isdir(rawFolder):
print(rawFolder + " is not a valid directory")
exit()
gwentDataHelper = GwentUtils.GwentDataHelper(rawFolder)
BASE_FILENAME = datetime.utcnow().strftime("%Y-%m-%d") + ".json"
print("Creating keyword JSON...")
keywordsJson = KeywordData.create_keyword_json(gwentDataHelper)
filename = "keywords_" + BASE_FILENAME
filepath = os.path.join(rawFolder + "../" + filename)
GwentUtils.save_json(filepath, keywordsJson)
print("Creating categories JSON...")
categoriesJson = CategoryData.create_category_json(gwentDataHelper)
filename = "categories_" + BASE_FILENAME
filepath = os.path.join(rawFolder + "../" + filename)
GwentUtils.save_json(filepath, categoriesJson)
print("Creating card data JSON...")
cardsJson = CardData.create_card_json(gwentDataHelper)
filename = "cards_" + BASE_FILENAME
filepath = os.path.join(rawFolder + "../" + filename)
print("Found %s cards." % (len(cardsJson)))
GwentUtils.save_json(filepath, cardsJson)